Skip to content

Commit

Permalink
misc. updates
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Sep 3, 2016
1 parent 755cd05 commit 4ac407d
Show file tree
Hide file tree
Showing 16 changed files with 189 additions and 141 deletions.
35 changes: 23 additions & 12 deletions libmscore/chord.cpp
Expand Up @@ -54,6 +54,17 @@

namespace Ms {

//---------------------------------------------------------
// LedgerLineData
//---------------------------------------------------------

struct LedgerLineData {
int line;
qreal minX, maxX;
bool visible;
bool accidental;
};

//---------------------------------------------------------
// upNote / downNote
//---------------------------------------------------------
Expand Down Expand Up @@ -655,7 +666,7 @@ void Chord::addLedgerLines()
delta = -1;
}
for (int i = from; i < n && i >=0 ; i += delta) {
const Note* note = _notes.at(i);
Note* note = _notes.at(i);
int l = note->physicalLine();

// if 1st pass and note not below staff or 2nd pass and note not above staff
Expand All @@ -681,19 +692,19 @@ void Chord::addLedgerLines()

// check if note horiz. pos. is outside current range
// if more length on the right, increase range
// note->layout();
x = note->pos().x();
if (x-extraLen < minX) {
if (x - extraLen < minX) {
minX = x - extraLen;
// minXr = minX - extraLen;
// increase width of all lines between this one and the staff
for (auto& d : vecLines)
for (auto& d : vecLines) {
if (!d.accidental && ((l < 0 && d.line >= l) || (l > 0 && d.line <= l)) )
d.minX = minX ;
}
}
// same for left side
if (x+hw+extraLen > maxX) {
if (x + hw + extraLen > maxX) {
maxX = x + hw + extraLen;
// maxXr = maxX + extraLen;
for (auto& d : vecLines)
if ( (l < 0 && d.line >= l) || (l > 0 && d.line <= l) )
d.maxX = maxX;
Expand Down Expand Up @@ -736,7 +747,7 @@ void Chord::addLedgerLines()
h->setParent(this);
h->setTrack(track);
h->setVisible(lld.visible && staffVisible);
h->setLen(Spatium( (lld.maxX - lld.minX) / _spatium) );
h->setLen(lld.maxX - lld.minX);
h->setPos(lld.minX, lld.line * _spatium * stepDistance);
h->setNext(_ledgerLines);
_ledgerLines = h;
Expand Down Expand Up @@ -1502,7 +1513,7 @@ void Chord::layout2()
int etrack = strack + VOICES;

for (LedgerLine* h = _ledgerLines; h; h = h->next()) {
Spatium len(h->len());
qreal len = h->len();
qreal y = h->y();
qreal x = h->x();
bool found = false;
Expand All @@ -1516,15 +1527,15 @@ void Chord::layout2()
if (ll->y() != y)
continue;

qreal d = cx - ll->measureXPos() - (ll->len().val() * _spatium);
qreal d = cx - ll->measureXPos() - ll->len();
if (d < minDist) {
//
// the ledger lines overlap
//
qreal shorten = (minDist - d) * .5;
x += shorten;
len -= Spatium(shorten / _spatium);
ll->setLen(ll->len() - Spatium(shorten / _spatium));
len -= shorten;
ll->setLen(ll->len() - shorten);
h->setLen(len);
h->setPos(x, y);
}
Expand Down Expand Up @@ -2154,7 +2165,7 @@ void Chord::layoutTablature()
ldgLin->setParent(this);
ldgLin->setTrack(track());
ldgLin->setVisible(_visible);
ldgLin->setLen(Spatium( (headWidth + extraLen) / _spatium) );
ldgLin->setLen(headWidth + extraLen);
ldgLin->setPos(llX, llY);
ldgLin->setNext(_ledgerLines);
_ledgerLines = ldgLin;
Expand Down
7 changes: 0 additions & 7 deletions libmscore/chord.h
Expand Up @@ -63,13 +63,6 @@ enum class PlayEventType : char {
class Chord : public ChordRest {
Q_OBJECT

struct LedgerLineData {
int line;
qreal minX, maxX;
bool visible;
bool accidental;
};

Q_PROPERTY(Ms::Beam* beam READ beam)
Q_PROPERTY(QQmlListProperty<Ms::Chord> graceNotes READ qmlGraceNotes)
Q_PROPERTY(Ms::Hook* hook READ hook)
Expand Down
52 changes: 15 additions & 37 deletions libmscore/element.cpp
Expand Up @@ -969,30 +969,14 @@ Line::Line(Score* s, bool v)
}

//---------------------------------------------------------
// dump
//---------------------------------------------------------

void Line::dump() const
{
qDebug(" width:%g height:%g vert:%d", point(_width), point(_len), vertical);
}

//---------------------------------------------------------
// setLen
//---------------------------------------------------------

void Line::setLen(Spatium l)
{
_len = l;
}

//---------------------------------------------------------
// setLineWidth
// spatiumChanged
//---------------------------------------------------------

void Line::setLineWidth(Spatium w)
void Line::spatiumChanged(qreal oldValue, qreal newValue)
{
_width = w;
_width = (_width / oldValue) * newValue;
_len = (_len / oldValue) * newValue;
layout();
}

//---------------------------------------------------------
Expand All @@ -1001,14 +985,11 @@ void Line::setLineWidth(Spatium w)

void Line::layout()
{
qreal sp = spatium();
qreal w = _width.val() * sp;
qreal l = _len.val() * sp;
qreal w2 = w * .5;
qreal w2 = _width * .5;
if (vertical)
bbox().setRect(-w2, -w2, w, l + w);
bbox().setRect(-w2, -w2, _width, _len + _width);
else
bbox().setRect(-w2, -w2, l + w, w);
bbox().setRect(-w2, -w2, _len + _width, _width);
}

//---------------------------------------------------------
Expand All @@ -1017,14 +998,11 @@ void Line::layout()

void Line::draw(QPainter* painter) const
{
qreal sp = spatium();
painter->setPen(QPen(curColor(), _width.val() * sp));

qreal l = _len.val() * sp;
painter->setPen(QPen(curColor(), _width));
if (vertical)
painter->drawLine(QLineF(0.0, 0.0, 0.0, l));
painter->drawLine(QLineF(0.0, 0.0, 0.0, _len));
else
painter->drawLine(QLineF(0.0, 0.0, l, 0.0));
painter->drawLine(QLineF(0.0, 0.0, _len, 0.0));
}

//---------------------------------------------------------
Expand All @@ -1033,8 +1011,8 @@ void Line::draw(QPainter* painter) const

void Line::writeProperties(Xml& xml) const
{
xml.tag("lineWidth", _width.val());
xml.tag("lineLen", _len.val());
xml.tag("lineWidth", _width / spatium());
xml.tag("lineLen", _len / spatium());
if (!vertical)
xml.tag("vertical", vertical);
}
Expand All @@ -1048,9 +1026,9 @@ bool Line::readProperties(XmlReader& e)
const QStringRef& tag(e.name());

if (tag == "lineWidth")
_width = Spatium(e.readDouble());
_width = e.readDouble() * spatium();
else if (tag == "lineLen")
_len = Spatium(e.readDouble());
_len = e.readDouble() * spatium();
else if (tag == "vertical")
vertical = e.readInt();
else
Expand Down
23 changes: 12 additions & 11 deletions libmscore/element.h
Expand Up @@ -881,8 +881,8 @@ class StaffLines : public Element {
class Line : public Element {
Q_OBJECT

Spatium _width;
Spatium _len;
qreal _width;
qreal _len;

protected:
bool vertical;
Expand All @@ -892,19 +892,20 @@ class Line : public Element {
Line(Score*, bool vertical);
Line &operator=(const Line&);

virtual Line* clone() const { return new Line(*this); }
virtual Element::Type type() const { return Element::Type::LINE; }
virtual void layout();
virtual Line* clone() const override { return new Line(*this); }
virtual Element::Type type() const override { return Element::Type::LINE; }
virtual void layout() override;

virtual void draw(QPainter*) const;
virtual void draw(QPainter*) const override;
void writeProperties(Xml& xml) const;
bool readProperties(XmlReader&);
void dump() const;

Spatium len() const { return _len; }
Spatium lineWidth() const { return _width; }
void setLen(Spatium);
void setLineWidth(Spatium);
qreal len() const { return _len; }
qreal lineWidth() const { return _width; }
void setLen(qreal v) { _len = v; }
void setLineWidth(qreal v) { _width = v; }

virtual void spatiumChanged(qreal /*oldValue*/, qreal /*newValue*/) override;
};

//---------------------------------------------------------
Expand Down
32 changes: 13 additions & 19 deletions libmscore/layout.cpp
Expand Up @@ -1956,25 +1956,19 @@ qreal Score::computeMinWidth(Segment* s, bool isFirstMeasureInSystem)
qreal x;

Shape ls;
if (s->isChordRestType()) {
// x = qMax(s->minLeft() + styleP(StyleIdx::minNoteDistance), styleP(StyleIdx::barNoteDistance));
x = s->minLeft() + styleP(StyleIdx::barNoteDistance);
}
else {
if (isFirstMeasureInSystem)
ls.add(QRectF(0.0, -1000000.0, 0.0, 2000000.0)); // left margin
else
ls.add(QRectF(0.0, 0.0, 0.0, spatium() * 4)); // simulated bar line
x = s->minLeft(ls);

if (s->isClefType())
// x = qMax(x, clefLeftMargin);
x += styleP(StyleIdx::clefLeftMargin);
else if (s->isKeySigType())
x = qMax(x, styleP(StyleIdx::keysigLeftMargin));
else if (s->isTimeSigType())
x = qMax(x, styleP(StyleIdx::timesigLeftMargin));
}
if (isFirstMeasureInSystem)
ls.add(QRectF(0.0, -1000000.0, 0.0, 2000000.0)); // hard left margin
else
ls.add(QRectF(0.0, 0.0, 0.0, spatium() * 4)); // simulated bar line
x = s->minLeft(ls);
if (s->isChordRestType())
x += styleP(StyleIdx::barNoteDistance);
else if (s->isClefType())
x += styleP(StyleIdx::clefLeftMargin);
else if (s->isKeySigType())
x = qMax(x, styleP(StyleIdx::keysigLeftMargin));
else if (s->isTimeSigType())
x = qMax(x, styleP(StyleIdx::timesigLeftMargin));

x += s->extraLeadingSpace().val() * spatium();
bool isSystemHeader = isFirstMeasureInSystem;
Expand Down
4 changes: 2 additions & 2 deletions libmscore/ledgerline.cpp
Expand Up @@ -60,7 +60,7 @@ qreal LedgerLine::measureXPos() const

void LedgerLine::layout()
{
setLineWidth(score()->styleS(StyleIdx::ledgerLineWidth) * chord()->mag());
setLineWidth(score()->styleP(StyleIdx::ledgerLineWidth) * chord()->mag());
if (staff())
setColor(staff()->color());
Line::layout();
Expand All @@ -72,7 +72,7 @@ void LedgerLine::layout()

void LedgerLine::draw(QPainter* painter) const
{
if(chord()->crossMeasure() == CrossMeasure::SECOND)
if (chord()->crossMeasure() == CrossMeasure::SECOND)
return;
Line::draw(painter);
}
Expand Down
33 changes: 33 additions & 0 deletions libmscore/mscore.cpp
Expand Up @@ -109,6 +109,9 @@ int MScore::mtcType;
bool MScore::noExcerpts = false;
bool MScore::noImages = false;
bool MScore::pdfPrinting = false;
double MScore::pixelRatio = 0.8; // DPI / logicalDPI

MPaintDevice* MScore::_paintDevice;

#ifdef SCRIPT_INTERFACE
QQmlEngine* MScore::_qml = 0;
Expand Down Expand Up @@ -439,6 +442,36 @@ QQmlEngine* MScore::qml()
}
return _qml;
}

//---------------------------------------------------------
// paintDevice
//---------------------------------------------------------

MPaintDevice* MScore::paintDevice()
{
if (!_paintDevice)
_paintDevice = new MPaintDevice();
return _paintDevice;
}

int MPaintDevice::metric(PaintDeviceMetric m) const
{
switch (m) {
case QPaintDevice::PdmDpiY:
return int(DPI);
default:
printf("debug: metric %d\n", int(m));
return 1;
}
return 0;
}

QPaintEngine* MPaintDevice::paintEngine() const
{
printf("paint engine\n");
return 0;
}

#endif
}

0 comments on commit 4ac407d

Please sign in to comment.