Exemplo n.º 1
0
bool ScoreView::editElementDragTransition(QMouseEvent* ev)
      {
      data.startMove = toLogical(ev->pos());
      data.lastPos   = data.startMove;
      data.pos       = data.startMove;
      data.view      = this;

      Element* e = elementNear(data.startMove);
      if (e && (e == editObject) && (editObject->isText())) {
            if (editObject->mousePress(data.startMove, ev)) {
                  _score->addRefresh(editObject->canvasBoundingRect());
                  _score->end();
                  }
            return true;
            }
      int i = 0;
      if (grips) {
            qreal a = grip[0].width() * 1.0;
            for (; i < grips; ++i) {
                  if (grip[i].adjusted(-a, -a, a, a).contains(data.startMove)) {
                        curGrip = Grip(i);
                        data.curGrip = Grip(i);
                        updateGrips();
                        score()->end();
                        break;
                        }
                  }
            }
      return i != grips;
      }
Exemplo n.º 2
0
void ChordLine::updateGrips(Grip* defaultGrip, QVector<QRectF>& grip) const
      {
      int n = path.elementCount();
      QPointF cp(pagePos());
      qreal sp = spatium();
      if (_straight) {
            // limit the number of grips to one
            float offset = 0.5 * sp;

            if (_chordLineType == ChordLineType::FALL)
                  grip[0].translate(QPointF(offset, -offset));
            else if (_chordLineType == ChordLineType::DOIT)
                   grip[0].translate(QPointF(offset, offset));
            else if (_chordLineType == ChordLineType::SCOOP)
                   grip[0].translate(QPointF(-offset, offset));
            else if (_chordLineType == ChordLineType::PLOP)
                   grip[0].translate(QPointF(-offset, -offset));

            // translate on the length and height - stops the grips from goint past boundries of slide
            grip[0].translate(cp + QPointF(path.elementAt(1).x * sp, path.elementAt(1).y * sp));
            }
      else  {
            *defaultGrip = Grip(n - 1);
            for (int i = 0; i < n; ++i)
                  grip[i].translate(cp + QPointF(path.elementAt(i).x * sp, path.elementAt(i).y * sp));

            }
      }
Exemplo n.º 3
0
void Lasso::updateGrips(Grip* defaultGrip, QVector<QRectF>& r) const
{
    *defaultGrip = Grip(7);
    r[0].translate(_rect.topLeft());
    r[1].translate(_rect.topRight());
    r[2].translate(_rect.bottomRight());
    r[3].translate(_rect.bottomLeft());
    r[4].translate(_rect.x() + _rect.width() * .5, _rect.top());
    r[5].translate(_rect.right(), _rect.y() + _rect.height() * .5);
    r[6].translate(_rect.x() + _rect.width()*.5, _rect.bottom());
    r[7].translate(_rect.left(), _rect.y() + _rect.height() * .5);
}
Exemplo n.º 4
0
void Image::startEdit(EditData& ed)
      {
      Element::startEdit(ed);
      ed.grips   = 2;
      ed.curGrip = Grip(1);
      }
Exemplo n.º 5
0
void ChordLine::editDrag(const EditData& ed)
      {
      int n = path.elementCount();
      QPainterPath p;
      qreal sp = spatium();
      _lengthX += ed.delta.x();
      _lengthY += ed.delta.y();

      // used to limit how grips can affect the slide, stops the user from being able to turn one kind of slide into another
      int slideBoundary = 5;
      if ((_chordLineType == ChordLineType::PLOP || _chordLineType == ChordLineType::FALL) && _lengthY < -slideBoundary)
            _lengthY = -slideBoundary;
      else if ((_chordLineType == ChordLineType::FALL || _chordLineType == ChordLineType::DOIT) && _lengthX < -slideBoundary)
            _lengthX = -slideBoundary;
      else if ((_chordLineType == ChordLineType::DOIT || _chordLineType == ChordLineType::SCOOP) && _lengthY > slideBoundary)
            _lengthY = slideBoundary;
      else if ((_chordLineType == ChordLineType::SCOOP || _chordLineType == ChordLineType::PLOP)  && _lengthX > slideBoundary)
            _lengthX = slideBoundary;

      qreal dx = ed.delta.x() / sp;
      qreal dy = ed.delta.y() / sp;
      for (int i = 0; i < n; ++i) {
            const QPainterPath::Element& e = (_straight ? path.elementAt(1) : path.elementAt(i));
            if (_straight) {
                  if (i > 0)
                        break;
                  // check the gradient of the line
                  const QPainterPath::Element& startPoint = path.elementAt(0);
                  if ( (_chordLineType == ChordLineType::FALL && (e.x + dx < startPoint.x || e.y + dy < startPoint.y))  ||
                       (_chordLineType == ChordLineType::DOIT && (e.x + dx < startPoint.x || e.y + dy > startPoint.y))  ||
                       (_chordLineType == ChordLineType::SCOOP && (e.x + dx > startPoint.x || e.y + dy < startPoint.y)) ||
                       (_chordLineType == ChordLineType::PLOP && (e.x + dx > startPoint.x || e.y + dy > startPoint.y)) )
                              return;
                  }

            qreal x = e.x;
            qreal y = e.y;
            if (ed.curGrip == Grip(i)) {
                  x += dx;
                  y += dy;
                  }
            switch(e.type) {
                  case QPainterPath::CurveToDataElement:
                        break;
                  case QPainterPath::MoveToElement:
                        p.moveTo(x, y);
                        break;
                  case QPainterPath::LineToElement:
                        p.lineTo(x, y);
                        break;
                  case QPainterPath::CurveToElement:
                        {
                        qreal x2 = path.elementAt(i+1).x;
                        qreal y2 = path.elementAt(i+1).y;
                        qreal x3 = path.elementAt(i+2).x;
                        qreal y3 = path.elementAt(i+2).y;
                        if (Grip(i + 1) == ed.curGrip) {
                              x2 += dx;
                              y2 += dy;
                              }
                        else if (Grip(i + 2) == ed.curGrip) {
                              x3 += dx;
                              y3 += dy;
                              }
                        p.cubicTo(x, y, x2, y2, x3, y3);
                        i += 2;
                        }
                        break;
                  }
            }
      path = p;
      modified = true;
      }
Exemplo n.º 6
0
int main()
{
  //access the simpleIDE terminal
  simpleterm_close();
  //set full-duplex serialization for the terminal
  term = fdserial_open(31, 30, 0, 9600);

  char c;

  //servo_angle(16, gripDegree); //Orient gripper to half open on start
  //pause(3000);

  while (1)
  {
    c = fdserial_rxChar(term); //Get the character entered from the terminal
    if (c != -1)
    {
      //Use the below to see if any key input is being read by the terminal
      // dprint(term, "You typed: %c\n", c);

      //Link key presses to directional commands, and print the command to strings
      if (c == 'f') //press "f" fof forward
      {           
        Drive(ticks, ticks, maxSpeed);
        dprint(term, "ok\n");
      } 
      else if (c == 'b') //press "b" for backward
      { 
        Drive(-ticks, -ticks, maxSpeed);
        dprint(term, "ok\n");
      } 
      else if (c == 'r') //press "r" for right turn
      { 
        Drive(turnTick, -turnTick, maxTurnSpeed);
        dprint(term, "ok\n");
      } 
      else if (c == 'l') //press "l" for left turn
      { 
        Drive(-turnTick, turnTick, maxTurnSpeed);
        dprint(term, "ok\n");
      } 

      //Increasing and Decreasing Drive Speed
      else if (c == 'u') 
      {
        ticks = ticks + 2;
        if (ticks > maxSpeed) //clamp speed so it can't go over the maximum speed
        {
           ticks = maxSpeed;
        }
        dprint(term, "move_speed %d\n", ticks);
      } 
      else if (c == 'd') 
      {
        ticks = ticks - 2;
        if (ticks < minSpeed) //clamp speed so it can't go negative or 0
        {
          ticks = minSpeed;
        }
        dprint(term, "move_speed %d\n", ticks);
      }

      //Increase Turn Speed;
      else if (c == 't') 
      {
        turnTick = turnTick + 1;
        if (turnTick > maxTurnSpeed)
        {
          turnTick = maxTurnSpeed;
        }
        dprint(term, "turn_speed %d\n", turnTick);
      }
      
      //decrease turn speed
      else if (c == 'n')
      {
        turnTick = turnTick - 1;
        if (turnTick < minTurnSpeed)
          {
          turnTick = minTurnSpeed;
          }
        dprint(term, "turn_speed %d\n", turnTick);
      }

      else if (c == 'p') //ping distance
      {
        pingDistance = ping(8);
        dprint(term, "echo %d\n", pingDistance);
        dprint(term, "ok\n");
      }

      else if (c == 'k') // poke
      {
      }
      else if (c == 'o') //open gripper
      {
        gripState = 0;
        gripDegree = -1800;
      }
      else if (c == 'g') //close gripper
      {
        gripState = 1;
        gripDegree = 1800;
      }
    } // End of Read Character Function
  if (gripState != -1) 
  {
    Grip(gripDegree, 2000);
  }
  } // End of While Loop
} //End of Main Loop