MuseScore/libmscore/barline.h

155 lines
6.2 KiB
C
Raw Normal View History

2012-05-26 14:26:10 +02:00
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2002-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 __BARLINE_H__
#define __BARLINE_H__
#include "element.h"
2013-05-13 18:49:17 +02:00
class QPainter;
namespace Ms {
2012-05-26 14:26:10 +02:00
class MuseScoreView;
class Segment;
2016-02-09 13:51:19 +01:00
static const int DEFAULT_BARLINE_TO = 4 * 2;
static const int MIN_BARLINE_FROMTO_DIST = 2;
static const int MIN_BARLINE_SPAN_FROMTO = -2;
// bar line span for 1-line staves is special: goes from 2sp above the line to 2sp below the line;
2016-02-09 13:51:19 +01:00
static const int BARLINE_SPAN_1LINESTAFF_FROM = -4;
static const int BARLINE_SPAN_1LINESTAFF_TO = 4;
// data for some preset bar line span types
static const int BARLINE_SPAN_TICK1_FROM = -1;
static const int BARLINE_SPAN_TICK1_TO = 1;
static const int BARLINE_SPAN_TICK2_FROM = -2;
static const int BARLINE_SPAN_TICK2_TO = 2;
static const int BARLINE_SPAN_SHORT1_FROM = 2;
static const int BARLINE_SPAN_SHORT1_TO = 6;
static const int BARLINE_SPAN_SHORT2_FROM = 1;
static const int BARLINE_SPAN_SHORT2_TO = 7;
// used while reading a score for a default spanTo (to last staff line) toward a staff not yet read;
// fixed once all staves are read
2016-02-09 13:51:19 +01:00
static const int UNKNOWN_BARLINE_TO = -6;
2015-02-25 11:54:31 +01:00
//---------------------------------------------------------
// BarLineTableItem
//---------------------------------------------------------
struct BarLineTableItem {
BarLineType type;
2016-02-04 17:06:32 +01:00
const char* userName; // user name, translatable
2015-02-25 11:54:31 +01:00
const char* name;
};
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
2012-07-25 11:49:34 +02:00
// @@ BarLine
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
class BarLine : public Element {
Q_OBJECT
BarLineType _barLineType { BarLineType::NORMAL };
2016-02-09 13:51:19 +01:00
int _span { 1 }; // number of staves spanned by the barline
int _spanFrom { 0 }; // line number on start and end staves
int _spanTo { DEFAULT_BARLINE_TO };
2016-03-08 09:46:33 +01:00
bool _customSpan { false };
// static variables used while dragging
static int _origSpan, _origSpanFrom, _origSpanTo; // original span value before editing
2012-10-14 00:35:11 +02:00
static qreal yoff1, yoff2; // used during drag edit to extend y1 and y2
static bool ctrlDrag; // used to mark if [CTRL] has been used while dragging
static bool shiftDrag; // used to mark if [SHIFT] has been used while dragging
2012-05-26 14:26:10 +02:00
void getY(qreal*, qreal*) const;
ElementList _el; ///< fermata or other articulations
void drawDots(QPainter* painter, qreal x) const;
public:
BarLine(Score*);
2014-06-27 13:41:49 +02:00
BarLine &operator=(const BarLine&) = delete;
2012-05-26 14:26:10 +02:00
virtual BarLine* clone() const override { return new BarLine(*this); }
virtual Element::Type type() const override { return Element::Type::BAR_LINE; }
virtual void write(Xml& xml) const override;
virtual void read(XmlReader&) override;
virtual void draw(QPainter*) const override;
virtual QPointF pagePos() const override; ///< position in canvas coordinates
virtual void layout() override;
virtual void scanElements(void* data, void (*func)(void*, Element*), bool all=true) override;
virtual void add(Element*) override;
virtual void remove(Element*) override;
2016-01-04 14:48:58 +01:00
virtual QPainterPath outline() const override;
2014-08-13 21:01:21 +02:00
virtual bool acceptDrop(const DropData&) const override;
virtual Element* drop(const DropData&) override;
virtual bool isEditable() const override { return true; }
2016-02-09 13:51:19 +01:00
Segment* segment() const { return (Segment*)parent(); }
2016-02-04 11:27:47 +01:00
2016-02-09 13:51:19 +01:00
void setSpan(int val) { _span = val; }
void setSpanFrom(int val) { _spanFrom = val; }
void setSpanTo(int val) { _spanTo = val; }
int span() const { return _span; }
int spanFrom() const { return _spanFrom; }
int spanTo() const { return _spanTo; }
2016-03-08 09:46:33 +01:00
bool customSpan() const { return _customSpan; }
void setCustomSpan(bool v) { _customSpan = v; }
2012-05-26 14:26:10 +02:00
virtual void startEdit(MuseScoreView*, const QPointF&) override;
virtual void endEdit() override;
virtual void editDrag(const EditData&) override;
virtual void endEditDrag() override;
virtual void updateGrips(Grip*, QVector<QRectF>&) const override;
virtual int grips() const override { return 2; }
ElementList* el() { return &_el; }
const ElementList* el() const { return &_el; }
2012-05-26 14:26:10 +02:00
2014-03-24 11:50:26 +01:00
static QString userTypeName(BarLineType);
2016-02-04 17:06:32 +01:00
static const BarLineTableItem* barLineTableItem(unsigned);
QString barLineTypeName() const;
static QString barLineTypeName(BarLineType t);
void setBarLineType(const QString& s);
2016-02-09 13:51:19 +01:00
void setBarLineType(BarLineType i) { _barLineType = i; }
BarLineType barLineType() const { return _barLineType; }
2016-01-04 14:48:58 +01:00
static BarLineType barLineType(const QString&);
2012-05-26 14:26:10 +02:00
virtual int subtype() const override { return int(_barLineType); }
virtual QString subtypeName() const override { return qApp->translate("barline", barLineTypeName().toUtf8()); }
2016-03-08 09:46:33 +01:00
2014-03-24 11:50:26 +01:00
virtual QVariant getProperty(P_ID propertyId) const override;
virtual bool setProperty(P_ID propertyId, const QVariant&) override;
virtual QVariant propertyDefault(P_ID propertyId) const override;
2012-05-26 14:26:10 +02:00
virtual qreal mag() const override;
static void setCtrlDrag(bool val) { ctrlDrag = val; }
static void setShiftDrag(bool val) { shiftDrag = val; }
2012-08-02 18:33:43 +02:00
static qreal layoutWidth(Score*, BarLineType, qreal mag);
virtual Element* nextElement() override;
virtual Element* prevElement() override;
2016-02-04 17:06:32 +01:00
virtual QString accessibleInfo() const override;
virtual QString accessibleExtraInfo() const override;
2012-05-26 14:26:10 +02:00
};
2013-05-13 18:49:17 +02:00
} // namespace Ms
2012-05-26 14:26:10 +02:00
#endif