MuseScore/libmscore/spanner.h

187 lines
6.1 KiB
C
Raw Normal View History

2012-05-26 14:26:10 +02:00
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2010-2011 Werner Schweer
//
// 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 __SPANNER_H__
#define __SPANNER_H__
#include "element.h"
2013-05-13 18:49:17 +02:00
namespace Ms {
2012-05-26 14:26:10 +02:00
class Segment;
class Spanner;
class System;
2013-06-16 23:33:37 +02:00
class Chord;
2013-06-10 11:03:34 +02:00
class ChordRest;
//---------------------------------------------------------
// SpannerSegmentType
//---------------------------------------------------------
2012-05-26 14:26:10 +02:00
enum class SpannerSegmentType : char {
SINGLE, BEGIN, MIDDLE, END
2012-05-26 14:26:10 +02:00
};
//---------------------------------------------------------
2012-07-25 11:49:34 +02:00
// @@ SpannerSegment
//! parent: System
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
class SpannerSegment : public Element {
Q_OBJECT
2012-05-26 14:26:10 +02:00
Spanner* _spanner;
2013-06-10 11:03:34 +02:00
SpannerSegmentType _spannerSegmentType;
protected:
QPointF _p2;
QPointF _userOff2;
2012-05-26 14:26:10 +02:00
public:
SpannerSegment(Score* s);
SpannerSegment(const SpannerSegment&);
virtual SpannerSegment* clone() const = 0;
2013-06-10 11:03:34 +02:00
2012-05-26 14:26:10 +02:00
Spanner* spanner() const { return _spanner; }
Spanner* setSpanner(Spanner* val) { return _spanner = val; }
void setSpannerSegmentType(SpannerSegmentType s) { _spannerSegmentType = s; }
SpannerSegmentType spannerSegmentType() const { return _spannerSegmentType; }
2012-05-26 14:26:10 +02:00
void setSystem(System* s);
System* system() const { return (System*)parent(); }
2013-06-10 11:03:34 +02:00
const QPointF& userOff2() const { return _userOff2; }
void setUserOff2(const QPointF& o) { _userOff2 = o; }
void setUserXoffset2(qreal x) { _userOff2.setX(x); }
void setPos2(const QPointF& p) { _p2 = p; }
QPointF pos2() const { return _p2 + _userOff2; }
const QPointF& ipos2() const { return _p2; }
virtual void startEdit(MuseScoreView*, const QPointF&) override;
virtual void endEdit() override;
virtual bool isEditable() const override { return true; }
2013-05-02 16:12:17 +02:00
virtual QVariant getProperty(P_ID id) const override;
virtual bool setProperty(P_ID id, const QVariant& v) override;
virtual QVariant propertyDefault(P_ID id) const override;
2013-08-26 10:39:16 +02:00
virtual void reset() override;
2014-05-07 12:10:28 +02:00
virtual void setSelected(bool f) override;
virtual void setVisible(bool f) override;
2012-05-26 14:26:10 +02:00
};
2012-09-12 11:16:36 +02:00
//----------------------------------------------------------------------------------
2012-07-16 19:59:32 +02:00
// @@ Spanner
/// Virtual base class for slurs, ties, lines etc.
//
// @P tick int tick start position
// @P tick2 int tick end position
2014-05-26 20:48:27 +02:00
// @P anchor Ms::Spanner::Anchor (SEGMENT, MEASURE, CHORD, NOTE)
2012-09-12 11:16:36 +02:00
//----------------------------------------------------------------------------------
2012-05-26 14:26:10 +02:00
class Spanner : public Element {
Q_OBJECT
2012-09-12 11:16:36 +02:00
Q_ENUMS(Anchor)
public:
2014-05-26 20:48:27 +02:00
enum class Anchor : char {
SEGMENT, MEASURE, CHORD, NOTE
2012-09-12 11:16:36 +02:00
};
private:
Q_PROPERTY(int tick READ tick WRITE setTick)
Q_PROPERTY(int tick2 READ tick2 WRITE setTick2)
Q_PROPERTY(Ms::Spanner::Anchor anchor READ anchor WRITE setAnchor)
2012-05-26 14:26:10 +02:00
QList<SpannerSegment*> segments;
2014-05-26 20:48:27 +02:00
Anchor _anchor = Anchor::SEGMENT;
2013-10-14 11:56:54 +02:00
Element* _startElement = 0;
Element* _endElement = 0;
int _tick = -1;
int _tick2 = -1;
2013-09-27 11:18:30 +02:00
int _track2 = -1;
2012-05-26 14:26:10 +02:00
2013-06-10 11:03:34 +02:00
static QList<QPointF> userOffsets;
static QList<QPointF> userOffsets2;
2012-05-26 14:26:10 +02:00
2013-07-05 11:23:52 +02:00
protected:
2013-09-27 11:18:30 +02:00
static int editTick, editTick2, editTrack2;
2014-07-10 14:32:04 +02:00
static Element* editStartElement;
static Element* editEndElement;
2013-07-05 11:23:52 +02:00
2012-05-26 14:26:10 +02:00
public:
Spanner(Score* = 0);
2012-05-26 14:26:10 +02:00
Spanner(const Spanner&);
~Spanner();
virtual Element::Type type() const = 0;
2013-08-22 12:18:14 +02:00
virtual void setScore(Score* s) override;
2012-05-26 14:26:10 +02:00
int tick() const { return _tick; }
void setTick(int v) { _tick = v; }
int tickLen() const { return _tick2 - _tick; }
int tick2() const { return _tick2; }
void setTick2(int v) { _tick2 = v; }
2013-09-27 11:18:30 +02:00
int track2() const { return _track2; }
void setTrack2(int v) { _track2 = v; }
2012-05-26 14:26:10 +02:00
Anchor anchor() const { return _anchor; }
void setAnchor(Anchor a) { _anchor = a; }
const QList<SpannerSegment*>& spannerSegments() const { return segments; }
QList<SpannerSegment*>& spannerSegments() { return segments; }
2013-08-22 12:18:14 +02:00
virtual void add(Element*) override;
virtual void remove(Element*) override;
virtual void scanElements(void* data, void (*func)(void*, Element*), bool all=true) override;
virtual void startEdit(MuseScoreView*, const QPointF&) override;
virtual void endEdit() override;
2012-05-26 14:26:10 +02:00
bool removeSpannerBack();
2014-05-26 20:48:27 +02:00
virtual void setYoff(qreal) {} // used in musicxml import
2012-09-12 11:16:36 +02:00
2013-06-10 11:03:34 +02:00
QVariant getProperty(P_ID propertyId) const;
bool setProperty(P_ID propertyId, const QVariant& v);
QVariant propertyDefault(P_ID propertyId) const;
2013-06-16 23:33:37 +02:00
void computeStartElement();
void computeEndElement();
Element* startElement() const { return _startElement; }
2013-06-19 16:25:29 +02:00
Element* endElement() const { return _endElement; }
2013-06-16 23:33:37 +02:00
void setStartElement(Element* e) { _startElement = e; }
void setEndElement(Element* e) { _endElement = e; }
void setStartChord(Chord*);
void setEndChord(Chord*);
Chord* startChord();
Chord* endChord();
2013-06-16 23:33:37 +02:00
ChordRest* startCR();
ChordRest* endCR();
2013-06-16 23:33:37 +02:00
2013-06-10 11:03:34 +02:00
Segment* startSegment() const;
Segment* endSegment() const;
2014-05-07 12:10:28 +02:00
virtual void setSelected(bool f) override;
virtual void setVisible(bool f) override;
friend class SpannerSegment;
2013-06-10 11:03:34 +02:00
};
2013-05-13 18:49:17 +02:00
} // namespace Ms
Q_DECLARE_METATYPE(Ms::Spanner::Anchor);
2013-05-13 18:49:17 +02:00
2012-05-26 14:26:10 +02:00
#endif