Пример #1
0
QPainterPath LineItem::rightMidGrip() const {
  if (gripMode() == Move)
    return QPainterPath();

  QRectF bound = gripBoundingRect();
  QRectF grip = QRectF(bound.topRight() - QPointF(sizeOfGrip().width(), 0), sizeOfGrip());
  grip.moveCenter(QPointF(grip.center().x(), bound.center().y()));
  QPainterPath path;
  if (gripMode() == Resize || gripMode() == Scale)
    path.addRect(grip);
  else
    path.addEllipse(grip);

  return path;
}
Пример #2
0
void LabelItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
  ViewItem::mouseMoveEvent(event);

  if ((gripMode() == ViewItem::Resize) && (activeGrip() != NoGrip)) {
    _resized = true;
  }

}
Пример #3
0
QPainterPath LineItem::grips() const {
  if (gripMode() == Move)
    return QPainterPath();

  QPainterPath grips;
  grips.addPath(leftMidGrip());
  grips.addPath(rightMidGrip());
  return grips;
}
Пример #4
0
void LineItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {

  if (view()->viewMode() == View::Data) {
    event->ignore();
    return;
  }

  if (!dragStartPosition.isNull() && event->buttons() & Qt::LeftButton) {
    if (view()->mouseMode() == View::Move) {
      startDragging(event->widget(), dragStartPosition.toPoint());
      return;
    }
  }

  if (view()->mouseMode() == View::Default) {
    if (gripMode() == ViewItem::Move || activeGrip() == NoGrip) {
      view()->setMouseMode(View::Move);
      view()->undoStack()->beginMacro(tr("Move"));
    } else if (gripMode() == ViewItem::Resize) {
      view()->setMouseMode(View::Resize);
      view()->undoStack()->beginMacro(tr("Resize"));
    }
  }

  if (activeGrip() == NoGrip)
    return QGraphicsRectItem::mouseMoveEvent(event);

  double width = 0;
  double height = 0;
  double theta = 0;
  QPointF centerP;
  QPointF P1, P2;

  if (gripMode() == ViewItem::Resize) {
    switch(activeGrip()) {
    case RightMidGrip:
      P1 = mapToParent(QPoint(rect().left(), rect().center().y()));
      P2 = mapToParent(event->pos());
      break;
    case LeftMidGrip:
      P1 = mapToParent(event->pos());
      P2 = mapToParent(QPoint(rect().right(), rect().center().y()));
      break;
    default:
      return;
    }
    centerP = (P1 + P2) * 0.5;
    theta = atan2(P2.y() - P1.y(), P2.x() - P1.x());
    height = rect().height();
    double dx = P1.x() - P2.x();
    double dy = P1.y() - P2.y();
    width = sqrt(dx*dx + dy*dy)+1.0;

    if (activeGrip() == RightMidGrip) {
      setPos(P1);
      setViewRect(0,-height*0.5,width,height);
    } else if (activeGrip() == LeftMidGrip) {
      setPos(P2);
      setViewRect(-width, -height*0.5, width, height);
    }
    //setPos(centerP.x(), centerP.y());
    //setViewRect(-width*0.5, -height*0.5, width, height);

    QTransform transform;
    transform.rotateRadians(theta);

    setTransform(transform);
    updateRelativeSize(true);
  }
}