Esempio n. 1
0
void LineSegment::editDrag(const EditData& ed)
      {
      // Only for resizing according to the diagonal properties
      QPointF deltaResize(ed.delta.x(), line()->diagonal() ? ed.delta.y() : 0.0);

      // Only for moving, no y limitaion
      QPointF deltaMove(ed.delta.x(), ed.delta.y());

      switch(ed.curGrip) {
            case GRIP_LINE_START: // Resize the begin of element (left grip)
                  setUserOff(userOff() + deltaResize);
                  _userOff2 -= deltaResize;
                  break;
            case GRIP_LINE_END: // Resize the end of element (rigth grip)
                  _userOff2 += deltaResize;
                  break;
            case GRIP_LINE_MIDDLE: // Move the element (middle grip)
                  setUserOff(userOff() + deltaMove);
                  break;
            }
      if ((line()->anchor() == Spanner::ANCHOR_NOTE)
         && (ed.curGrip == GRIP_LINE_START || ed.curGrip == GRIP_LINE_END)) {
            //
            // if we touch a different note, change anchor
            //
            Element* e = ed.view->elementNear(ed.pos);
            if (e && e->type() == NOTE) {
                  SLine* l = line();
                  if (ed.curGrip == GRIP_LINE_END && e != line()->endElement()) {
                        qDebug("LineSegment: move end anchor");
                        Note* noteOld = static_cast<Note*>(l->endElement());
                        Note* noteNew = static_cast<Note*>(e);

                        noteOld->removeSpannerBack(l);
                        noteNew->addSpannerBack(l);
                        l->setEndElement(noteNew);

                        _userOff2 += noteOld->canvasPos() - noteNew->canvasPos();
                        }
                  else if (ed.curGrip == GRIP_LINE_START && e != l->startElement()) {
                        qDebug("LineSegment: move start anchor (not impl.)");
                        }
                  }
            }
      line()->layout();
      }
Esempio n. 2
0
bool SLine::is_vertical_to(SLine &other_line, int epsilon)
{
    int dot_prod = dot_product(other_line);
    if(epsilon)
    {
        //calculate
        double norm1 = norm();
        double norm2 = other_line.norm();
        double cosfi = dot_prod/norm1/norm2;
        double fi = acos(cosfi);
        if(std::abs(DEGREE_TO_RAD(90.0)-fi) < epsilon)
            return true;
    }
    else
        return static_cast<bool>(std::abs(dot_prod) < 0.000001);
    return false;
}
Esempio n. 3
0
bool SLine::is_parallel_to(SLine &other_line, int epsilon)
{
    double dot_prod = static_cast<double>(dot_product(other_line));
    if(dot_prod < 0.0000001)
        return false;
    double norm1 = norm();
    double norm2 = other_line.norm();
    double cosfi = dot_prod/norm1/norm2;
    double fi = acos(cosfi);
    double diff = std::abs(DEGREE_TO_RAD(0.0)-fi);
    if(epsilon)
    {
        if(diff < epsilon)
        //calculate
            return true;
    }
    else
    {
        return static_cast<bool>(std::abs(fi) < 0.000001);
    }
    return false;
}
Esempio n. 4
0
bool LineSegment::edit(MuseScoreView* sv, int curGrip, int key, Qt::KeyboardModifiers modifiers, const QString&)
      {
      if (!((modifiers & Qt::ShiftModifier)
         && ((subtype() == SEGMENT_SINGLE)
              || (subtype() == SEGMENT_BEGIN && curGrip == GRIP_LINE_START)
              || (subtype() == SEGMENT_END && curGrip == GRIP_LINE_END))))
            return false;

      LineSegment* ls = 0;
      SLine* l        = line();
      bool bspDirty   = false;
      SpannerSegmentType st = subtype();
      int track   = l->track();

      if (l->anchor() == ANCHOR_SEGMENT) {
            Segment* s1 = static_cast<Segment*>(l->startElement());
            Segment* s2 = static_cast<Segment*>(l->endElement());

            bool removeSegment = false;

            if (key == Qt::Key_Left) {
                  if (curGrip == GRIP_LINE_START) {
                        s1 = prevSeg1(s1, track);
                        }
                  else if (curGrip == GRIP_LINE_END) {
                        s2 = prevSeg1(s2, track);
                        if (s2
                           && (s2->system()->firstMeasure() == s2->measure())
                           && (s2->tick() == s2->measure()->tick())) {
                              removeSegment = true;
                              }
                        }
                  }
            else if (key == Qt::Key_Right) {
                  if (curGrip == GRIP_LINE_START)
                        s1 = nextSeg1(s1, track);
                  else if (curGrip == GRIP_LINE_END) {
                        if ((s2->system()->firstMeasure() == s2->measure())
                           && (s2->tick() == s2->measure()->tick()))
                              bspDirty = true;
                        s2 = nextSeg1(s2, track);
                        }
                  }
            if (s1 == 0 || s2 == 0 || s1->tick() >= s2->tick())
                  return true;

            if (l->startElement() != s1) {
                  if (s1->system() != (static_cast<Segment*>(l->startElement())->system())) {
                        bspDirty = true;
                        if (key == Qt::Key_Right)
                              ls = l->takeFirstSegment();
                        }
                  static_cast<Segment*>(l->startElement())->remove(l);
                  l->setStartElement(s1);
                  s1->add(l);
                  }
            else if (l->endElement() != s2) {
                  if (removeSegment) {
                        bspDirty = true;
                        if (key == Qt::Key_Left)
                              ls = l->takeLastSegment();
                        }

                  static_cast<Segment*>(l->endElement())->removeSpannerBack(l);
                  l->setEndElement(s2);
                  s2->addSpannerBack(l);
                  }
            }
      else {
            Measure* m1 = static_cast<Measure*>(l->startElement());
            Measure* m2 = static_cast<Measure*>(l->endElement());

            bool removeSegment = false;

            if (key == Qt::Key_Left) {
                  if (curGrip == GRIP_LINE_START) {
                        if (m1->prevMeasure())
                              m1 = m1->prevMeasure();
                        }
                  else if (curGrip == GRIP_LINE_END) {
                        if (m2 && (m2->system()->firstMeasure() == m2))
                              removeSegment = true;
                        Measure* m = m2->prevMeasure();
                        if (m)
                              m2 = m;
                        }
                  }
            else if (key == Qt::Key_Right) {
                  if (curGrip == GRIP_LINE_START) {
                        if (m1->nextMeasure())
                              m1 = m1->nextMeasure();
                        }
                  else if (curGrip == GRIP_LINE_END) {
                        if (m2->nextMeasure())
                              m2 = m2->nextMeasure();
                        if (m2->system()->firstMeasure() == m2)
                              bspDirty = true;
                        }
                  }
            if (m1->tick() > m2->tick())
                  return true;

            if (l->startElement() != m1) {
                  if (m1->system() != (static_cast<Measure*>(l->startElement())->system())) {
                        bspDirty = true;
                        if (key == Qt::Key_Right)
                              ls = l->takeFirstSegment();
                        }
                  l->startElement()->remove(l);
                  l->setStartElement(m1);
                  m1->add(l);
                  }
            else if (l->endElement() != m2) {
                  if (removeSegment) {
                        bspDirty = true;
                        if (key == Qt::Key_Left)
                              ls = l->takeLastSegment();
                        }
                  static_cast<Measure*>(l->endElement())->removeSpannerBack(l);
                  l->setEndElement(m2);
                  m2->addSpannerBack(l);
                  }
            }
      l->layout();

      LineSegment* nls = 0;
      if (st == SEGMENT_SINGLE) {
            if (curGrip == GRIP_LINE_START)
                  nls = l->frontSegment();
            else if (curGrip == GRIP_LINE_END)
                  nls = l->backSegment();
            }
      else if (st == SEGMENT_BEGIN)
            nls = l->frontSegment();
      else if (st == SEGMENT_END)
            nls = l->backSegment();

      if (nls && (nls != this))
            sv->changeEditElement(nls);
      if (bspDirty)
            _score->rebuildBspTree();
      if (ls)
            _score->undoRemoveElement(ls);
      return true;
      }
Esempio n. 5
0
int SLine::dot_product(SLine &other_line)
{
    return dx()*other_line.dx()+ dy()*other_line.dy();
}