2012-05-26 14:26:10 +02:00
|
|
|
//=============================================================================
|
|
|
|
// MuseScore
|
|
|
|
// Music Composition & Notation
|
|
|
|
//
|
2017-01-18 14:16:33 +01:00
|
|
|
// Copyright (C) 2002-2017 Werner Schweer
|
2012-05-26 14:26:10 +02:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License version 2
|
|
|
|
// as published by the Free Software Foundation and appearing in
|
|
|
|
// the file LICENCE.GPL
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
#ifndef __ELEMENT_H__
|
|
|
|
#define __ELEMENT_H__
|
|
|
|
|
2013-05-13 18:49:17 +02:00
|
|
|
#include "spatium.h"
|
2014-04-09 16:09:21 +02:00
|
|
|
#include "fraction.h"
|
2015-02-04 22:12:13 +01:00
|
|
|
#include "scoreElement.h"
|
2016-01-04 14:48:58 +01:00
|
|
|
#include "shape.h"
|
2013-05-13 18:49:17 +02:00
|
|
|
|
|
|
|
namespace Ms {
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2018-01-31 19:58:43 +01:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
#define CONTROL_MODIFIER Qt::AltModifier
|
|
|
|
#else
|
|
|
|
#define CONTROL_MODIFIER Qt::ControlModifier
|
|
|
|
#endif
|
|
|
|
|
2017-01-18 22:41:58 +01:00
|
|
|
#ifndef VOICES
|
|
|
|
#define VOICES 4
|
|
|
|
#endif
|
2016-02-04 11:27:47 +01:00
|
|
|
|
2018-05-26 20:01:06 +02:00
|
|
|
class ConnectorInfoReader;
|
2017-01-18 22:41:58 +01:00
|
|
|
class XmlReader;
|
|
|
|
class XmlWriter;
|
2014-06-24 17:16:22 +02:00
|
|
|
enum class SymId;
|
2018-03-27 15:36:00 +02:00
|
|
|
enum class Pid;
|
2018-10-18 11:53:01 +02:00
|
|
|
enum class OffsetType : char;
|
2019-01-30 15:13:54 +01:00
|
|
|
class StaffType;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2015-01-19 12:37:17 +01:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// Grip
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2017-06-23 12:40:47 +02:00
|
|
|
enum class Grip {
|
2015-01-19 12:37:17 +01:00
|
|
|
NO_GRIP = -1,
|
|
|
|
START = 0, END = 1, // arpeggio etc.
|
|
|
|
MIDDLE = 2, APERTURE = 3, // Line
|
|
|
|
/*START, END , */
|
|
|
|
BEZIER1 = 2, SHOULDER = 3, BEZIER2 = 4, DRAG = 5, // Slur
|
|
|
|
GRIPS = 6 // number of grips for slur
|
|
|
|
};
|
2014-07-10 14:13:37 +02:00
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// ElementFlag
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2016-10-20 11:32:07 +02:00
|
|
|
enum class ElementFlag {
|
2018-10-18 11:53:01 +02:00
|
|
|
NOTHING = 0x00000000,
|
|
|
|
DROP_TARGET = 0x00000001,
|
|
|
|
NOT_SELECTABLE = 0x00000002,
|
|
|
|
MOVABLE = 0x00000004,
|
|
|
|
COMPOSITION = 0x00000008, // true if element is part of another element
|
|
|
|
HAS_TAG = 0x00000010, // true if this is a layered element
|
|
|
|
ON_STAFF = 0x00000020,
|
|
|
|
SELECTED = 0x00000040,
|
|
|
|
GENERATED = 0x00000080,
|
|
|
|
INVISIBLE = 0x00000100,
|
|
|
|
NO_AUTOPLACE = 0x00000200,
|
|
|
|
SYSTEM = 0x00000400,
|
|
|
|
PLACE_ABOVE = 0x00000800,
|
|
|
|
SIZE_SPATIUM_DEPENDENT = 0x00001000,
|
2016-10-20 11:32:07 +02:00
|
|
|
|
|
|
|
// measure flags
|
2018-10-18 11:53:01 +02:00
|
|
|
REPEAT_END = 0x00002000,
|
|
|
|
REPEAT_START = 0x00004000,
|
|
|
|
REPEAT_JUMP = 0x00008000,
|
|
|
|
IRREGULAR = 0x00010000,
|
|
|
|
LINE_BREAK = 0x00020000,
|
|
|
|
PAGE_BREAK = 0x00040000,
|
|
|
|
SECTION_BREAK = 0x00080000,
|
|
|
|
NO_BREAK = 0x00100000,
|
|
|
|
HEADER = 0x00200000,
|
|
|
|
TRAILER = 0x00400000, // also used in segment
|
|
|
|
KEYSIG = 0x00800000,
|
2018-04-09 11:51:35 +02:00
|
|
|
|
2016-10-20 11:32:07 +02:00
|
|
|
// segment flags
|
2018-10-18 11:53:01 +02:00
|
|
|
ENABLED = 0x01000000, // used for segments
|
|
|
|
EMPTY = 0x02000000,
|
|
|
|
WRITTEN = 0x04000000,
|
2012-05-26 14:26:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef QFlags<ElementFlag> ElementFlags;
|
2014-05-16 13:48:03 +02:00
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(ElementFlags);
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2017-03-31 13:03:15 +02:00
|
|
|
class ElementEditData;
|
2017-03-04 15:01:42 +01:00
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// EditData
|
|
|
|
// used in editDrag
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2017-04-11 11:34:25 +02:00
|
|
|
class EditData {
|
|
|
|
QList<ElementEditData*> data;
|
|
|
|
|
|
|
|
public:
|
|
|
|
MuseScoreView* view { 0 };
|
2017-03-31 13:03:15 +02:00
|
|
|
|
|
|
|
QVector<QRectF> grip;
|
2017-04-11 11:34:25 +02:00
|
|
|
int grips { 0 }; // number of grips
|
2017-03-31 13:03:15 +02:00
|
|
|
Grip curGrip { Grip(0) };
|
2016-12-29 13:42:55 +01:00
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
QPointF pos;
|
2017-03-31 13:03:15 +02:00
|
|
|
QPointF startMove;
|
2017-06-13 17:23:11 +02:00
|
|
|
QPoint startMovePixel;
|
2014-05-05 12:25:17 +02:00
|
|
|
QPointF lastPos;
|
|
|
|
QPointF delta;
|
2017-03-31 13:03:15 +02:00
|
|
|
bool hRaster { false };
|
|
|
|
bool vRaster { false };
|
|
|
|
|
2017-04-11 11:34:25 +02:00
|
|
|
int key { 0 };
|
|
|
|
Qt::KeyboardModifiers modifiers { 0 };
|
2017-03-31 13:03:15 +02:00
|
|
|
QString s;
|
|
|
|
|
2017-05-03 16:20:04 +02:00
|
|
|
Qt::MouseButtons buttons { Qt::NoButton };
|
|
|
|
|
2017-03-31 13:03:15 +02:00
|
|
|
// drop data:
|
|
|
|
QPointF dragOffset;
|
2017-04-11 11:34:25 +02:00
|
|
|
Element* element { 0 };
|
2018-11-13 13:31:48 +01:00
|
|
|
Element* dropElement { 0 };
|
2017-04-11 11:34:25 +02:00
|
|
|
Fraction duration { Fraction(1,4) };
|
|
|
|
|
2017-06-19 12:59:53 +02:00
|
|
|
EditData(MuseScoreView* v) : view(v) {}
|
2017-04-11 11:34:25 +02:00
|
|
|
void init();
|
|
|
|
void clearData();
|
2017-03-31 13:03:15 +02:00
|
|
|
|
2017-06-02 10:27:32 +02:00
|
|
|
ElementEditData* getData(const Element*) const;
|
2017-03-04 15:01:42 +01:00
|
|
|
void addData(ElementEditData*);
|
2018-10-10 18:55:23 +02:00
|
|
|
bool control(bool textEditing = false) const;
|
2017-07-26 09:59:24 +02:00
|
|
|
bool shift() const { return modifiers & Qt::ShiftModifier; }
|
|
|
|
bool isStartEndGrip() { return curGrip == Grip::START || curGrip == Grip::END; }
|
2012-05-26 14:26:10 +02:00
|
|
|
};
|
|
|
|
|
2012-07-11 21:29:42 +02:00
|
|
|
//-------------------------------------------------------------------
|
|
|
|
// @@ Element
|
2014-05-16 13:44:32 +02:00
|
|
|
/// \brief Base class of score layout elements
|
2012-07-16 19:59:32 +02:00
|
|
|
///
|
2014-05-16 13:44:32 +02:00
|
|
|
/// The Element class is the virtual base class of all
|
|
|
|
/// score layout elements.
|
2012-07-11 21:29:42 +02:00
|
|
|
//-------------------------------------------------------------------
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2017-01-18 14:16:33 +01:00
|
|
|
class Element : public ScoreElement {
|
2015-03-31 17:34:54 +02:00
|
|
|
Element* _parent { 0 };
|
2018-10-18 11:53:01 +02:00
|
|
|
mutable QRectF _bbox; ///< Bounding box relative to _pos + _offset
|
2012-05-26 14:26:10 +02:00
|
|
|
qreal _mag; ///< standard magnification (derived value)
|
|
|
|
QPointF _pos; ///< Reference position, relative to _parent.
|
2018-10-18 11:53:01 +02:00
|
|
|
QPointF _offset; ///< offset from reference position, set by autoplace or user
|
2019-05-04 08:01:00 +02:00
|
|
|
qreal _offsetAdjust; ///< portion of offset attributable to autoplace
|
|
|
|
bool _fixed; ///< offset is fixed, not changed by layout
|
2018-10-18 11:53:01 +02:00
|
|
|
int _track; ///< staffIdx * VOICES + voice
|
|
|
|
mutable ElementFlags _flags;
|
2012-05-26 14:26:10 +02:00
|
|
|
///< valid after call to layout()
|
|
|
|
uint _tag; ///< tag bitmask
|
2016-02-06 22:03:43 +01:00
|
|
|
|
2018-01-16 13:38:17 +01:00
|
|
|
protected:
|
|
|
|
mutable int _z;
|
|
|
|
QColor _color; ///< element color attribute
|
2019-05-04 08:01:00 +02:00
|
|
|
bool _offsetChanged; ///< set by user actions, checked and cleared during layout
|
2018-01-16 13:38:17 +01:00
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
public:
|
2018-02-01 15:36:20 +01:00
|
|
|
Element(Score* = 0, ElementFlags = ElementFlag::NOTHING);
|
2012-05-26 14:26:10 +02:00
|
|
|
Element(const Element&);
|
2017-03-31 13:03:15 +02:00
|
|
|
virtual ~Element();
|
2016-03-30 22:33:04 +02:00
|
|
|
|
2014-06-27 13:41:49 +02:00
|
|
|
Element &operator=(const Element&) = delete;
|
2015-04-24 00:55:46 +02:00
|
|
|
//@ create a copy of the element
|
2013-07-13 18:41:16 +02:00
|
|
|
Q_INVOKABLE virtual Ms::Element* clone() const = 0;
|
2012-05-26 14:26:10 +02:00
|
|
|
virtual Element* linkedClone();
|
2015-02-12 11:41:39 +01:00
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
Element* parent() const { return _parent; }
|
|
|
|
void setParent(Element* e) { _parent = e; }
|
2018-12-28 10:22:20 +01:00
|
|
|
Measure* findMeasure();
|
|
|
|
const Measure* findMeasure() const;
|
2018-05-23 00:32:33 +02:00
|
|
|
MeasureBase* findMeasureBase();
|
|
|
|
const MeasureBase* findMeasureBase() const;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2018-07-07 13:11:55 +02:00
|
|
|
virtual bool isElement() const override { return true; }
|
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
qreal spatium() const;
|
|
|
|
|
2016-10-20 11:32:07 +02:00
|
|
|
inline void setFlag(ElementFlag f, bool v) { if (v) _flags |= f; else _flags &= ~ElementFlags(f); }
|
|
|
|
inline void setFlag(ElementFlag f, bool v) const { if (v) _flags |= f; else _flags &= ~ElementFlags(f); }
|
|
|
|
inline bool flag(ElementFlag f) const { return _flags & f; }
|
|
|
|
|
|
|
|
bool selected() const { return flag(ElementFlag::SELECTED); }
|
|
|
|
virtual void setSelected(bool f) { setFlag(ElementFlag::SELECTED, f); }
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2018-07-04 12:41:03 +02:00
|
|
|
bool visible() const { return !flag(ElementFlag::INVISIBLE); }
|
|
|
|
virtual void setVisible(bool f) { setFlag(ElementFlag::INVISIBLE, !f); }
|
2012-10-31 14:21:13 +01:00
|
|
|
|
2018-10-18 11:53:01 +02:00
|
|
|
virtual bool sizeIsSpatiumDependent() const override { return !flag(ElementFlag::SIZE_SPATIUM_DEPENDENT); }
|
|
|
|
void setSizeIsSpatiumDependent(bool v) { setFlag(ElementFlag::SIZE_SPATIUM_DEPENDENT, !v); }
|
|
|
|
|
|
|
|
Placement placement() const { return Placement(!flag(ElementFlag::PLACE_ABOVE)); }
|
|
|
|
void setPlacement(Placement val) { setFlag(ElementFlag::PLACE_ABOVE, !bool(val)); }
|
|
|
|
bool placeAbove() const { return placement() == Placement::ABOVE; }
|
|
|
|
bool placeBelow() const { return placement() == Placement::BELOW; }
|
2012-10-31 14:21:13 +01:00
|
|
|
|
2016-10-20 11:32:07 +02:00
|
|
|
bool generated() const { return flag(ElementFlag::GENERATED); }
|
|
|
|
void setGenerated(bool val) { setFlag(ElementFlag::GENERATED, val); }
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2019-05-04 08:01:00 +02:00
|
|
|
bool fixed() const { return _fixed; }
|
|
|
|
void setFixed(bool v) { _fixed = v; }
|
|
|
|
bool offsetChanged() const { return _offsetChanged; }
|
|
|
|
void setOffsetChanged(bool v) { _offsetChanged = v; }
|
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
const QPointF& ipos() const { return _pos; }
|
2018-10-18 11:53:01 +02:00
|
|
|
virtual const QPointF pos() const { return _pos + _offset; }
|
|
|
|
virtual qreal x() const { return _pos.x() + _offset.x(); }
|
|
|
|
virtual qreal y() const { return _pos.y() + _offset.y(); }
|
2012-05-26 14:26:10 +02:00
|
|
|
void setPos(qreal x, qreal y) { _pos.rx() = x, _pos.ry() = y; }
|
|
|
|
void setPos(const QPointF& p) { _pos = p; }
|
2018-10-18 11:53:01 +02:00
|
|
|
QPointF& rpos() { return _pos; }
|
2012-05-26 14:26:10 +02:00
|
|
|
qreal& rxpos() { return _pos.rx(); }
|
|
|
|
qreal& rypos() { return _pos.ry(); }
|
|
|
|
virtual void move(const QPointF& s) { _pos += s; }
|
2019-05-04 08:01:00 +02:00
|
|
|
qreal offsetAdjust() const { return _offsetAdjust; }
|
|
|
|
void setOffsetAdjust(qreal v) { _offsetAdjust = v; }
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
virtual QPointF pagePos() const; ///< position in page coordinates
|
|
|
|
virtual QPointF canvasPos() const; ///< position in canvas coordinates
|
|
|
|
qreal pageX() const;
|
|
|
|
qreal canvasX() const;
|
|
|
|
|
2019-01-30 15:13:54 +01:00
|
|
|
const QPointF& offset() const { return _offset; }
|
|
|
|
virtual void setOffset(const QPointF& o) { _offset = o; }
|
|
|
|
void setOffset(qreal x, qreal y) { _offset.rx() = x, _offset.ry() = y; }
|
|
|
|
QPointF& roffset() { return _offset; }
|
|
|
|
qreal& rxoffset() { return _offset.rx(); }
|
|
|
|
qreal& ryoffset() { return _offset.ry(); }
|
|
|
|
|
|
|
|
virtual Fraction tick() const;
|
|
|
|
virtual Fraction rtick() const;
|
2018-10-18 11:53:01 +02:00
|
|
|
|
|
|
|
bool isNudged() const { return !_offset.isNull(); }
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2016-10-20 11:32:07 +02:00
|
|
|
virtual const QRectF& bbox() const { return _bbox; }
|
|
|
|
virtual QRectF& bbox() { return _bbox; }
|
|
|
|
virtual qreal height() const { return bbox().height(); }
|
|
|
|
virtual void setHeight(qreal v) { _bbox.setHeight(v); }
|
|
|
|
virtual qreal width() const { return bbox().width(); }
|
|
|
|
virtual void setWidth(qreal v) { _bbox.setWidth(v); }
|
2012-05-26 14:26:10 +02:00
|
|
|
QRectF abbox() const { return bbox().translated(pagePos()); }
|
|
|
|
QRectF pageBoundingRect() const { return bbox().translated(pagePos()); }
|
|
|
|
QRectF canvasBoundingRect() const { return bbox().translated(canvasPos()); }
|
|
|
|
virtual void setbbox(const QRectF& r) const { _bbox = r; }
|
|
|
|
virtual void addbbox(const QRectF& r) const { _bbox |= r; }
|
2016-12-29 13:42:55 +01:00
|
|
|
bool contains(const QPointF& p) const;
|
2012-05-26 14:26:10 +02:00
|
|
|
bool intersects(const QRectF& r) const;
|
2017-12-06 12:03:53 +01:00
|
|
|
#ifndef NDEBUG
|
|
|
|
virtual Shape shape() const { return Shape(bbox(), name()); }
|
|
|
|
#else
|
2017-01-19 16:06:40 +01:00
|
|
|
virtual Shape shape() const { return Shape(bbox()); }
|
2017-12-06 12:03:53 +01:00
|
|
|
#endif
|
2016-12-29 13:42:55 +01:00
|
|
|
virtual qreal baseLine() const { return -height(); }
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2017-01-18 14:16:33 +01:00
|
|
|
virtual int subtype() const { return -1; } // for select gui
|
2015-02-23 10:10:18 +01:00
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
virtual void draw(QPainter*) const {}
|
2016-05-18 15:43:47 +02:00
|
|
|
void drawAt(QPainter*p, const QPointF& pt) const { p->translate(pt); draw(p); p->translate(-pt);}
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2016-11-19 11:51:21 +01:00
|
|
|
virtual void writeProperties(XmlWriter& xml) const;
|
2013-07-31 11:05:48 +02:00
|
|
|
virtual bool readProperties(XmlReader&);
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2016-11-19 11:51:21 +01:00
|
|
|
virtual void write(XmlWriter&) const;
|
2013-01-11 18:10:18 +01:00
|
|
|
virtual void read(XmlReader&);
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2017-03-31 13:03:15 +02:00
|
|
|
virtual void startDrag(EditData&);
|
|
|
|
virtual QRectF drag(EditData&);
|
|
|
|
virtual void endDrag(EditData&);
|
2012-05-26 14:26:10 +02:00
|
|
|
virtual QLineF dragAnchor() const { return QLineF(); }
|
|
|
|
|
2016-10-20 11:32:07 +02:00
|
|
|
virtual bool isEditable() const { return !flag(ElementFlag::GENERATED); }
|
2017-03-31 13:03:15 +02:00
|
|
|
|
|
|
|
virtual void startEdit(EditData&);
|
|
|
|
virtual bool edit(EditData&);
|
2017-07-26 09:59:24 +02:00
|
|
|
virtual void startEditDrag(EditData&);
|
2017-03-31 13:03:15 +02:00
|
|
|
virtual void editDrag(EditData&);
|
2017-07-26 09:59:24 +02:00
|
|
|
virtual void endEditDrag(EditData&);
|
|
|
|
virtual void endEdit(EditData&);
|
|
|
|
|
2017-04-11 11:34:25 +02:00
|
|
|
virtual void editCut(EditData&) {}
|
|
|
|
virtual void editCopy(EditData&) {}
|
2017-03-31 13:03:15 +02:00
|
|
|
|
|
|
|
virtual void updateGrips(EditData&) const {}
|
|
|
|
virtual bool nextGrip(EditData&) const;
|
|
|
|
virtual bool prevGrip(EditData&) const;
|
|
|
|
virtual QPointF gripAnchor(Grip) const { return QPointF(); }
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
int track() const { return _track; }
|
|
|
|
virtual void setTrack(int val) { _track = val; }
|
|
|
|
|
2016-08-07 11:04:14 +02:00
|
|
|
int z() const;
|
|
|
|
void setZ(int val) { _z = val; }
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2013-01-02 20:13:58 +01:00
|
|
|
int staffIdx() const { return _track >> 2; }
|
2016-03-18 14:35:15 +01:00
|
|
|
virtual int vStaffIdx() const { return staffIdx(); }
|
2013-01-02 20:13:58 +01:00
|
|
|
int voice() const { return _track & 3; }
|
2015-04-25 11:43:09 +02:00
|
|
|
void setVoice(int v) { _track = (_track / VOICES) * VOICES + v; }
|
2012-05-26 14:26:10 +02:00
|
|
|
Staff* staff() const;
|
2019-01-30 15:13:54 +01:00
|
|
|
StaffType* staffType() const;
|
2015-03-05 16:46:37 +01:00
|
|
|
Part* part() const;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
virtual void add(Element*);
|
|
|
|
virtual void remove(Element*);
|
|
|
|
virtual void change(Element* o, Element* n);
|
|
|
|
|
|
|
|
virtual void layout() {}
|
|
|
|
virtual void spatiumChanged(qreal /*oldValue*/, qreal /*newValue*/);
|
2015-02-20 11:56:13 +01:00
|
|
|
virtual void localSpatiumChanged(qreal /*oldValue*/, qreal /*newValue*/);
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
// debug functions
|
|
|
|
virtual void dump() const;
|
2015-04-03 18:23:51 +02:00
|
|
|
virtual Q_INVOKABLE QString subtypeName() const;
|
2015-04-24 00:55:46 +02:00
|
|
|
//@ Returns the human-readable name of the element type
|
|
|
|
//@ Returns the name of the element type
|
2015-04-03 18:23:51 +02:00
|
|
|
virtual Q_INVOKABLE QString _name() const { return QString(name()); }
|
2012-05-26 14:26:10 +02:00
|
|
|
void dumpQPointF(const char*) const;
|
|
|
|
|
2015-03-20 09:58:41 +01:00
|
|
|
virtual QColor color() const { return _color; }
|
2012-05-26 14:26:10 +02:00
|
|
|
QColor curColor() const;
|
2018-05-07 11:28:27 +02:00
|
|
|
QColor curColor(bool isVisible) const;
|
2018-06-01 12:22:22 +02:00
|
|
|
QColor curColor(bool isVisible, QColor normalColor) const;
|
2014-10-01 15:15:08 +02:00
|
|
|
virtual void setColor(const QColor& c) { _color = c; }
|
2012-06-08 19:06:52 +02:00
|
|
|
void undoSetColor(const QColor& c);
|
2015-05-01 15:54:56 +02:00
|
|
|
void undoSetVisible(bool v);
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2017-01-18 14:16:33 +01:00
|
|
|
static ElementType readType(XmlReader& node, QPointF*, Fraction*);
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2019-03-26 10:49:58 +01:00
|
|
|
virtual QByteArray mimeData(const QPointF&) const;
|
2012-05-26 14:26:10 +02:00
|
|
|
/**
|
|
|
|
Return true if this element accepts a drop at canvas relative \a pos
|
|
|
|
of given element \a type and \a subtype.
|
|
|
|
|
|
|
|
Reimplemented by elements that accept drops. Used to change cursor shape while
|
|
|
|
dragging to indicate drop targets.
|
|
|
|
*/
|
2017-03-31 13:03:15 +02:00
|
|
|
virtual bool acceptDrop(EditData&) const { return false; }
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Handle a dropped element at canvas relative \a pos of given element
|
|
|
|
\a type and \a subtype. Returns dropped element if any.
|
2018-02-14 20:20:21 +01:00
|
|
|
The ownership of element in DropData is transferred to the called
|
2012-05-26 14:26:10 +02:00
|
|
|
element (if not used, element has to be deleted).
|
|
|
|
The returned element will be selected if not in note edit mode.
|
|
|
|
|
|
|
|
Reimplemented by elements that accept drops.
|
|
|
|
*/
|
2017-03-31 13:03:15 +02:00
|
|
|
virtual Element* drop(EditData&) { return 0;}
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
delivers mouseEvent to element in edit mode
|
|
|
|
returns true if mouse event is accepted by element
|
|
|
|
*/
|
2017-07-08 11:34:58 +02:00
|
|
|
virtual bool mousePress(EditData&) { return false; }
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2018-02-01 15:36:20 +01:00
|
|
|
mutable bool itemDiscovered { false }; ///< helper flag for bsp
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
virtual void scanElements(void* data, void (*func)(void*, Element*), bool all=true);
|
|
|
|
|
2018-03-28 17:49:08 +02:00
|
|
|
virtual void reset() override; // reset all properties & position to default
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2014-08-14 16:52:58 +02:00
|
|
|
virtual qreal mag() const { return _mag; }
|
2013-08-30 16:03:46 +02:00
|
|
|
void setMag(qreal val) { _mag = val; }
|
2014-08-14 16:52:58 +02:00
|
|
|
qreal magS() const;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2014-12-07 17:46:57 +01:00
|
|
|
bool isPrintable() const;
|
2012-05-26 14:26:10 +02:00
|
|
|
qreal point(const Spatium sp) const { return sp.val() * spatium(); }
|
|
|
|
|
|
|
|
//
|
|
|
|
// check element for consistency; return false if element
|
|
|
|
// is not valid
|
|
|
|
//
|
|
|
|
virtual bool check() const { return true; }
|
|
|
|
|
2017-01-18 14:16:33 +01:00
|
|
|
static Ms::Element* create(Ms::ElementType type, Score*);
|
2013-01-18 10:55:52 +01:00
|
|
|
static Element* name2Element(const QStringRef&, Score*);
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2018-08-01 11:46:07 +02:00
|
|
|
bool systemFlag() const { return flag(ElementFlag::SYSTEM); }
|
2017-01-17 10:16:15 +01:00
|
|
|
void setSystemFlag(bool v) const { setFlag(ElementFlag::SYSTEM, v); }
|
2016-10-20 11:32:07 +02:00
|
|
|
|
2016-10-25 17:30:55 +02:00
|
|
|
bool header() const { return flag(ElementFlag::HEADER); }
|
|
|
|
void setHeader(bool v) { setFlag(ElementFlag::HEADER, v); }
|
|
|
|
|
|
|
|
bool trailer() const { return flag(ElementFlag::TRAILER); }
|
|
|
|
void setTrailer(bool val) { setFlag(ElementFlag::TRAILER, val); }
|
|
|
|
|
2018-07-04 12:41:03 +02:00
|
|
|
bool selectable() const { return !flag(ElementFlag::NOT_SELECTABLE); }
|
|
|
|
void setSelectable(bool val) { setFlag(ElementFlag::NOT_SELECTABLE, !val); }
|
2016-10-20 11:32:07 +02:00
|
|
|
|
2014-05-22 10:10:58 +02:00
|
|
|
bool dropTarget() const { return flag(ElementFlag::DROP_TARGET); }
|
2016-10-20 11:32:07 +02:00
|
|
|
void setDropTarget(bool v) const { setFlag(ElementFlag::DROP_TARGET, v); }
|
|
|
|
|
2018-04-09 11:51:35 +02:00
|
|
|
bool composition() const { return flag(ElementFlag::COMPOSITION); }
|
|
|
|
void setComposition(bool v) const { setFlag(ElementFlag::COMPOSITION, v); }
|
|
|
|
|
2014-05-22 10:10:58 +02:00
|
|
|
virtual bool isMovable() const { return flag(ElementFlag::MOVABLE); }
|
2016-10-20 11:32:07 +02:00
|
|
|
|
|
|
|
bool enabled() const { return flag(ElementFlag::ENABLED); }
|
|
|
|
void setEnabled(bool val) { setFlag(ElementFlag::ENABLED, val); }
|
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
uint tag() const { return _tag; }
|
|
|
|
void setTag(uint val) { _tag = val; }
|
2016-10-20 11:32:07 +02:00
|
|
|
|
2019-02-25 06:12:17 +01:00
|
|
|
bool autoplace() const;
|
|
|
|
virtual void setAutoplace(bool v) { setFlag(ElementFlag::NO_AUTOPLACE, !v); }
|
|
|
|
bool addToSkyline() const { return !(_flags & (ElementFlag::INVISIBLE|ElementFlag::NO_AUTOPLACE)); }
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2018-03-27 15:36:00 +02:00
|
|
|
virtual QVariant getProperty(Pid) const override;
|
|
|
|
virtual bool setProperty(Pid, const QVariant&) override;
|
2018-11-25 22:49:07 +01:00
|
|
|
virtual void undoChangeProperty(Pid id, const QVariant&, PropertyFlags ps) override;
|
|
|
|
using ScoreElement::undoChangeProperty;
|
2018-03-27 15:36:00 +02:00
|
|
|
virtual QVariant propertyDefault(Pid) const override;
|
2018-09-26 12:54:45 +02:00
|
|
|
virtual Pid propertyId(const QStringRef& xmlName) const override;
|
|
|
|
virtual QString propertyUserValue(Pid) const override;
|
2018-07-24 15:48:24 +02:00
|
|
|
virtual Element* propertyDelegate(Pid) { return 0; } // return Spanner for SpannerSegment for some properties
|
2016-07-09 17:07:12 +02:00
|
|
|
|
2018-03-27 15:36:00 +02:00
|
|
|
bool custom(Pid) const;
|
2016-02-09 13:51:19 +01:00
|
|
|
virtual bool isUserModified() const;
|
2013-08-06 19:28:04 +02:00
|
|
|
|
2017-03-09 13:37:40 +01:00
|
|
|
void drawSymbol(SymId id, QPainter* p, const QPointF& o = QPointF(), qreal scale = 1.0) const;
|
2013-11-06 15:58:05 +01:00
|
|
|
void drawSymbol(SymId id, QPainter* p, const QPointF& o, int n) const;
|
2017-03-09 13:37:40 +01:00
|
|
|
void drawSymbols(const std::vector<SymId>&, QPainter* p, const QPointF& o = QPointF(), qreal scale = 1.0) const;
|
|
|
|
void drawSymbols(const std::vector<SymId>&, QPainter* p, const QPointF& o, const QSizeF& scale) const;
|
2013-11-11 15:11:28 +01:00
|
|
|
qreal symHeight(SymId id) const;
|
|
|
|
qreal symWidth(SymId id) const;
|
2016-01-04 14:48:58 +01:00
|
|
|
qreal symWidth(const std::vector<SymId>&) const;
|
2013-11-11 15:11:28 +01:00
|
|
|
QRectF symBbox(SymId id) const;
|
2016-01-04 14:48:58 +01:00
|
|
|
QRectF symBbox(const std::vector<SymId>&) const;
|
2015-06-03 10:23:01 +02:00
|
|
|
QPointF symStemDownNW(SymId id) const;
|
|
|
|
QPointF symStemUpSE(SymId id) const;
|
2014-05-12 05:00:54 +02:00
|
|
|
QPointF symCutOutNE(SymId id) const;
|
|
|
|
QPointF symCutOutNW(SymId id) const;
|
|
|
|
QPointF symCutOutSE(SymId id) const;
|
|
|
|
QPointF symCutOutSW(SymId id) const;
|
2015-05-08 08:57:24 +02:00
|
|
|
qreal symAdvance(SymId id) const;
|
2014-01-09 13:09:58 +01:00
|
|
|
bool symIsValid(SymId id) const;
|
2014-04-09 16:09:21 +02:00
|
|
|
|
2016-02-04 17:06:32 +01:00
|
|
|
bool concertPitch() const;
|
2017-05-12 20:16:02 +02:00
|
|
|
virtual Element* nextElement(); // selects the next score element, (notes, rests etc. as well as articulation etc.)
|
|
|
|
virtual Element* prevElement(); // selects the next score element, (notes, rests etc. as well as articulation etc.)
|
|
|
|
virtual Element* nextSegmentElement(); //< Used for navigation
|
|
|
|
virtual Element* prevSegmentElement(); //< next-element and prev-element command
|
2014-06-20 22:48:34 +02:00
|
|
|
|
2016-02-04 17:06:32 +01:00
|
|
|
virtual QString accessibleInfo() const; //< used to populate the status bar
|
2018-02-14 20:20:21 +01:00
|
|
|
virtual QString screenReaderInfo() const { //< by default returns accessibleInfo, but can be overridden
|
2016-02-04 17:06:32 +01:00
|
|
|
return accessibleInfo();
|
|
|
|
}
|
|
|
|
// if the screen-reader needs a special string (see note for example)
|
|
|
|
virtual QString accessibleExtraInfo() const { // used to return info that will be appended to accessibleInfo
|
|
|
|
return QString(); // and passed only to the screen-reader
|
|
|
|
}
|
|
|
|
|
2016-06-14 10:32:34 +02:00
|
|
|
virtual void triggerLayout() const;
|
2017-04-11 11:34:25 +02:00
|
|
|
virtual void drawEditMode(QPainter*, EditData&);
|
2018-02-01 10:37:12 +01:00
|
|
|
|
|
|
|
void autoplaceSegmentElement(qreal minDistance); // helper function
|
2018-09-12 12:05:17 +02:00
|
|
|
void autoplaceMeasureElement(qreal minDistance);
|
2019-05-04 08:01:00 +02:00
|
|
|
void autoplaceCalculateOffset(QRectF& r, qreal minDistance);
|
2018-03-27 15:36:00 +02:00
|
|
|
qreal styleP(Sid idx) const;
|
2017-03-31 13:03:15 +02:00
|
|
|
};
|
2016-06-14 10:32:34 +02:00
|
|
|
|
2017-03-31 13:03:15 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// ElementEditData
|
|
|
|
// holds element specific data during element editing:
|
|
|
|
//
|
|
|
|
// startEditDrag(EditData&) creates data and attaches it to EditData
|
|
|
|
// editDrag(EditData&)
|
|
|
|
// endEditDrag(EditData&) use data to create undo records
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
struct PropertyData {
|
2018-03-27 15:36:00 +02:00
|
|
|
Pid id;
|
2017-03-31 13:03:15 +02:00
|
|
|
QVariant data;
|
2012-05-26 14:26:10 +02:00
|
|
|
};
|
|
|
|
|
2017-03-31 13:03:15 +02:00
|
|
|
class ElementEditData {
|
|
|
|
public:
|
|
|
|
Element* e;
|
|
|
|
QList<PropertyData> propertyData;
|
|
|
|
|
2018-03-27 15:36:00 +02:00
|
|
|
void pushProperty(Pid pid) { propertyData.push_back(PropertyData({pid, e->getProperty(pid) })); }
|
2017-03-31 13:03:15 +02:00
|
|
|
};
|
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// ElementList
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2016-02-06 22:03:43 +01:00
|
|
|
class ElementList : public std::vector<Element*> {
|
2012-05-26 14:26:10 +02:00
|
|
|
public:
|
|
|
|
ElementList() {}
|
|
|
|
bool remove(Element*);
|
|
|
|
void replace(Element* old, Element* n);
|
2016-11-19 11:51:21 +01:00
|
|
|
void write(XmlWriter&) const;
|
|
|
|
void write(XmlWriter&, const char* name) const;
|
2012-05-26 14:26:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2012-07-25 11:49:34 +02:00
|
|
|
// @@ Compound
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
class Compound : public Element {
|
2014-05-13 17:53:31 +02:00
|
|
|
QList<Element*> elements;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
protected:
|
2014-05-13 17:53:31 +02:00
|
|
|
const QList<Element*>& getElements() const { return elements; }
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
Compound(Score*);
|
|
|
|
Compound(const Compound&);
|
2017-01-18 14:16:33 +01:00
|
|
|
virtual ElementType type() const = 0;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
virtual void draw(QPainter*) const;
|
|
|
|
virtual void addElement(Element*, qreal x, qreal y);
|
|
|
|
void clear();
|
|
|
|
virtual void setSelected(bool f);
|
|
|
|
virtual void setVisible(bool);
|
|
|
|
virtual void layout();
|
|
|
|
};
|
|
|
|
|
|
|
|
extern bool elementLessThan(const Element* const, const Element* const);
|
|
|
|
extern void collectElements(void* data, Element* e);
|
|
|
|
|
2013-05-13 18:49:17 +02:00
|
|
|
|
|
|
|
} // namespace Ms
|
|
|
|
|
2017-01-18 14:16:33 +01:00
|
|
|
Q_DECLARE_METATYPE(Ms::ElementType);
|
2012-09-13 18:01:34 +02:00
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
#endif
|
|
|
|
|