Skip to content

Commit

Permalink
fix #45581 manual object positioning is incorrect after staff size ch…
Browse files Browse the repository at this point in the history
…ange
  • Loading branch information
wschweer committed Feb 20, 2015
1 parent 41af30e commit 12b4b1c
Show file tree
Hide file tree
Showing 15 changed files with 189 additions and 123 deletions.
10 changes: 10 additions & 0 deletions libmscore/element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,16 @@ void Element::spatiumChanged(qreal oldValue, qreal newValue)
_readPos *= (newValue / oldValue);
}

//---------------------------------------------------------
// localSpatiumChanged
// the scale of a staff changed
//---------------------------------------------------------

void Element::localSpatiumChanged(qreal oldValue, qreal newValue)
{
_userOff *= (newValue / oldValue);
}

//---------------------------------------------------------
// spatium
//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions libmscore/element.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ class Element : public QObject, public ScoreElement {

virtual void layout() {}
virtual void spatiumChanged(qreal /*oldValue*/, qreal /*newValue*/);
virtual void localSpatiumChanged(qreal /*oldValue*/, qreal /*newValue*/);

// debug functions
virtual void dump() const;
Expand Down
10 changes: 10 additions & 0 deletions libmscore/harmony.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,16 @@ void Harmony::spatiumChanged(qreal oldValue, qreal newValue)
render();
}

//---------------------------------------------------------
// localSpatiumChanged
//---------------------------------------------------------

void Harmony::localSpatiumChanged(qreal oldValue, qreal newValue)
{
Text::localSpatiumChanged(oldValue, newValue);
render();
}

//---------------------------------------------------------
// textStyleChanged
//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions libmscore/harmony.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ class Harmony : public Text {
const ChordDescription* fromXml(const QString& s, const QList<HDegree>&);
const ChordDescription* fromXml(const QString& s);
virtual void spatiumChanged(qreal oldValue, qreal newValue) override;
virtual void localSpatiumChanged(qreal oldValue, qreal newValue) override;
virtual void textStyleChanged() override;
virtual QLineF dragAnchor() const override;
void setHarmony(const QString& s);
Expand Down
10 changes: 10 additions & 0 deletions libmscore/line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,16 @@ void LineSegment::spatiumChanged(qreal ov, qreal nv)
_userOff2 *= nv / ov;
}

//---------------------------------------------------------
// localSpatiumChanged
//---------------------------------------------------------

void LineSegment::localSpatiumChanged(qreal ov, qreal nv)
{
Element::localSpatiumChanged(ov, nv);
_userOff2 *= nv / ov;
}

//---------------------------------------------------------
// getProperty
//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions libmscore/line.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class LineSegment : public SpannerSegment {
virtual void draw(QPainter*) const = 0;
SLine* line() const { return (SLine*)spanner(); }
virtual void spatiumChanged(qreal, qreal) override;
virtual void localSpatiumChanged(qreal, qreal) override;

friend class SLine;
virtual void read(XmlReader&) override;
Expand Down
1 change: 1 addition & 0 deletions libmscore/score.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ class Score : public QObject {
MeasureBaseList _measures; // here are the notes
SpannerMap _spanner;
std::set<Spanner*> _unmanagedSpanner;

//
// generated objects during layout:
//
Expand Down
175 changes: 89 additions & 86 deletions libmscore/segment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1090,14 +1090,14 @@ Element* Segment::lastElement(int staff)
// Use firstElement, or lastElement instead of this
//---------------------------------------------------------

Element* Segment::getElement(int staff)
Element* Segment::getElement(int staff)
{
if (this->segmentType() == Segment::Type::ChordRest) {
return this->firstElement(staff);
if (segmentType() == Segment::Type::ChordRest) {
return firstElement(staff);
}
else if (this->segmentType() == Segment::Type::EndBarLine ||
this->segmentType() == Segment::Type::BarLine ||
this->segmentType() == Segment::Type::StartRepeatBarLine) {
else if (segmentType() == Segment::Type::EndBarLine ||
segmentType() == Segment::Type::BarLine ||
segmentType() == Segment::Type::StartRepeatBarLine) {
for (int i = staff; i >= 0; i--) {
if (!this->element(i*VOICES)) {
continue;
Expand All @@ -1114,83 +1114,86 @@ Element* Segment::lastElement(int staff)
return 0;
}

//--------------------------------------------------------
// firstInNextSegments
// Searches for the next segment that has elements on the
// active staff and returns its first element
//
// Uses firstElement so it also returns a barline if it
// spans into the active staff
//--------------------------------------------------------

Element* Segment::firstInNextSegments(int activeStaff)
{
Element* re = 0;
Segment* seg = this;
while (!re) {
seg = seg->next1MM(Segment::Type::All);
if (!seg) //end of staff, or score
break;

re = seg->firstElement(activeStaff);
}

if (re)
return re;

if (!seg) { //end of staff
seg = score()->firstSegment();
return seg->element( (activeStaff + 1) * VOICES );
}

return 0;
}


//--------------------------------------------------------
// firstInNextSegments
// Searches for the previous segment that has elements on
// the active staff and returns its last element
//
// Uses lastElement so it also returns a barline if it
// spans into the active staff
//--------------------------------------------------------

Element* Segment::lastInPrevSegments(int activeStaff)
{
Element* re = 0;
Segment* seg = this;

while (!re) {
seg = seg->prev1MM(Segment::Type::All);
if (!seg) //end of staff, or score
break;

re = seg->lastElement(activeStaff);
}

if (re)
return re;

if (!seg) { //end of staff
if (activeStaff -1 < 0) //end of score
return 0;

re = 0;
seg = score()->lastSegment();
while (true) {
if (seg->segmentType() == Segment::Type::EndBarLine)
score()->inputState().setTrack( (activeStaff -1) * VOICES ); //correction

if ((re = seg->lastElement(activeStaff -1)) != 0)
return re;

seg = seg->prev1(Segment::Type::All);
}
}

return 0;
}
//--------------------------------------------------------
// firstInNextSegments
// Searches for the next segment that has elements on the
// active staff and returns its first element
//
// Uses firstElement so it also returns a barline if it
// spans into the active staff
//--------------------------------------------------------

Element* Segment::firstInNextSegments(int activeStaff)
{
Element* re = 0;
Segment* seg = this;
while (!re) {
seg = seg->next1MM(Segment::Type::All);
if (!seg) //end of staff, or score
break;

re = seg->firstElement(activeStaff);
}

if (re)
return re;

if (!seg) { //end of staff
seg = score()->firstSegment();
return seg->element( (activeStaff + 1) * VOICES );
}

return 0;
}

//--------------------------------------------------------
// firstInNextSegments
// Searches for the previous segment that has elements on
// the active staff and returns its last element
//
// Uses lastElement so it also returns a barline if it
// spans into the active staff
//--------------------------------------------------------

Element* Segment::lastInPrevSegments(int activeStaff)
{
Element* re = 0;
Segment* seg = this;

while (!re) {
seg = seg->prev1MM(Segment::Type::All);
if (!seg) //end of staff, or score
break;

re = seg->lastElement(activeStaff);
}

if (re)
return re;

if (!seg) { //end of staff
if (activeStaff -1 < 0) //end of score
return 0;

re = 0;
seg = score()->lastSegment();
while (true) {
if (seg->segmentType() == Segment::Type::EndBarLine)
score()->inputState().setTrack( (activeStaff -1) * VOICES ); //correction

if ((re = seg->lastElement(activeStaff -1)) != 0)
return re;

seg = seg->prev1(Segment::Type::All);
}
}

return 0;
}

//---------------------------------------------------------
// accessibleExtraInfo
//---------------------------------------------------------

QString Segment::accessibleExtraInfo()
{
Expand Down Expand Up @@ -1251,9 +1254,9 @@ QString Segment::accessibleExtraInfo()
return rez + " " + startSpanners + " " + endSpanners;
}

//--------------------------------------------------------
// qmlAnnotations
//--------------------------------------------------------
//--------------------------------------------------------
// qmlAnnotations
//--------------------------------------------------------

QQmlListProperty<Ms::Element> Segment::qmlAnnotations()
{
Expand Down
42 changes: 41 additions & 1 deletion libmscore/staff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "instrtemplate.h"
#include "barline.h"
#include "ottava.h"
#include "harmony.h"

namespace Ms {

Expand Down Expand Up @@ -1073,6 +1074,8 @@ QVariant Staff::getProperty(P_ID id) const
return userMag();
case P_ID::COLOR:
return color();
case P_ID::SMALL:
return small();
default:
qDebug("Staff::setProperty: unhandled id");
return QVariant();
Expand All @@ -1086,12 +1089,21 @@ QVariant Staff::getProperty(P_ID id) const
bool Staff::setProperty(P_ID id, const QVariant& v)
{
switch (id) {
case P_ID::MAG:
case P_ID::MAG: {
double oldVal = mag();
setUserMag(v.toDouble());
scaleChanged(oldVal, mag());
}
break;
case P_ID::COLOR:
setColor(v.value<QColor>());
break;
case P_ID::SMALL: {
double oldVal = mag();
setSmall(v.toBool());
scaleChanged(oldVal, mag());
}
break;
default:
qDebug("Staff::setProperty: unhandled id");
break;
Expand All @@ -1111,9 +1123,37 @@ QVariant Staff::propertyDefault(P_ID id) const
return 1.0;
case P_ID::COLOR:
return QColor(Qt::black);
case P_ID::SMALL:
return false;
default:
return QVariant();
}
}

//---------------------------------------------------------
// scaleChanged
//---------------------------------------------------------

void Staff::scaleChanged(double oldVal, double newVal)
{
int staffIdx = idx();
int startTrack = staffIdx * VOICES;
int endTrack = startTrack + VOICES;
for (Segment* s = score()->firstSegment(); s; s = s->next1()) {
for (Element* e : s->annotations())
e->localSpatiumChanged(oldVal, newVal);
for (int track = startTrack; track < endTrack; ++track) {
if (s->element(track))
s->element(track)->localSpatiumChanged(oldVal, newVal);
}
}
for (auto i : score()->spanner()) {
Spanner* spanner = i.second;
if (spanner->staffIdx() == staffIdx) {
for (auto k : spanner->spannerSegments())
k->localSpatiumChanged(oldVal, newVal);
}
}
}
}

2 changes: 2 additions & 0 deletions libmscore/staff.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ class Staff : public QObject, public ScoreElement {
VeloList _velocities; ///< cached value
PitchList _pitchOffsets; ///< cached value

void scaleChanged(double oldValue, double newValue);

public:
Staff(Score* = 0);
~Staff();
Expand Down
5 changes: 5 additions & 0 deletions libmscore/timesig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,11 @@ void TimeSig::spatiumChanged(qreal /*oldValue*/, qreal /*newValue*/)
_needLayout = true;
}

void TimeSig::localSpatiumChanged(qreal /*oldValue*/, qreal /*newValue*/)
{
_needLayout = true;
}

//---------------------------------------------------------
// layout
//---------------------------------------------------------
Expand Down
Loading

0 comments on commit 12b4b1c

Please sign in to comment.