Ejemplo n.º 1
0
// get bbox transformed to top
CBBox2D
CQIllustratorShape::
getFlatBBox() const
{
  CBBox2D bbox = getBBox();

  if (! bbox.isSet())
    return bbox;

  if (! parent_)
    return bbox;

  // if parent transform pby parent flat matric
  const CMatrix2D &m = parent_->getFlatMatrix();

  CPoint2D p1 = m*bbox.getLL();
  CPoint2D p2 = m*bbox.getLR();
  CPoint2D p3 = m*bbox.getUL();
  CPoint2D p4 = m*bbox.getUR();

  CBBox2D bbox1(p1, p2);

  bbox1 += p3;
  bbox1 += p4;

  return bbox1;
}
Ejemplo n.º 2
0
void
CQIllustratorShape::
setBBox(const CBBox2D &bbox)
{
  checkoutShape(CQIllustratorData::ChangeType::GEOMETRY);

  moveTo(bbox.getLL());

  resizeTo(bbox.getWidth(), bbox.getHeight());

  checkinShape(CQIllustratorData::ChangeType::GEOMETRY);
}
Ejemplo n.º 3
0
void
CQIllustratorShape::
drawSelect(CQIllustratorShapeDrawer *drawer)
{
  CBBox2D bbox = getFlatBBox();

  if (bbox.isSet()) {
    CPoint2D p1 = bbox.getLL();
    CPoint2D p2 = bbox.getLR();
    CPoint2D p3 = bbox.getUR();
    CPoint2D p4 = bbox.getUL();

    drawer->drawControlLine(p1, p2);
    drawer->drawControlLine(p2, p3);
    drawer->drawControlLine(p3, p4);
    drawer->drawControlLine(p4, p1);
  }
}
void
CQIllustratorAlignMode::
align(CQIllustrator::AlignSide side, bool commit)
{
  CQIllustratorSelectedShapes *selection = illustrator_->getSelection();

  if (selection->empty()) return;

  //------

  if (illustrator_->getFlipY()) {
    if      (side == CQIllustrator::ALIGN_BOTTOM) side = CQIllustrator::ALIGN_TOP;
    else if (side == CQIllustrator::ALIGN_TOP   ) side = CQIllustrator::ALIGN_BOTTOM;
  }

  //------

  CQIllustratorShape *ashape = 0;

  CBBox2D abbox;
  CBBox2D bbbox;
  bool    afixed = false;

  CQIllustratorAlignToolbar::AnchorMode anchorMode = toolbar_->getAnchorMode();

  if      (anchorMode == CQIllustratorAlignToolbar::AnchorMode::SELECTION) {
    // get anchor shape for side

    CQIllustratorSelectedShapes::iterator ps1, ps2;

    ps1 = selection->begin();
    ps2 = selection->end();

    for ( ; ps1 != ps2; ++ps1) {
      CQIllustratorShape *shape = (*ps1).getShape();

      bbbox += shape->getFlatBBox();
    }

    ps1 = selection->begin();

    for ( ; ps1 != ps2; ++ps1) {
      CQIllustratorShape *shape = (*ps1).getShape();

      const CBBox2D &bbox = shape->getFlatBBox();

      if (! abbox.isSet() || (! afixed && shape->getFixed())) {
        ashape = shape;
        abbox  = bbox;
        afixed = ashape->getFixed();

        continue;
      }

      if (afixed && ! shape->getFixed())
        continue;

      if ((side == CQIllustrator::ALIGN_LEFT       && bbox.getXMin() < abbox.getXMin()) ||
          (side == CQIllustrator::ALIGN_BOTTOM     && bbox.getYMin() < abbox.getYMin()) ||
          (side == CQIllustrator::ALIGN_RIGHT      && bbox.getXMax() > abbox.getXMax()) ||
          (side == CQIllustrator::ALIGN_TOP        && bbox.getYMax() > abbox.getYMax()) ||
          (side == CQIllustrator::ALIGN_HORIZONTAL && bbox.getYMid() < abbox.getYMid()) ||
          (side == CQIllustrator::ALIGN_VERTICAL   && bbox.getXMid() < abbox.getXMid())) {
        ashape = shape;
        abbox  = bbox;
        afixed = ashape->getFixed();
      }
    }
  }
  else if (anchorMode == CQIllustratorAlignToolbar::AnchorMode::OBJECT) {
    CQIllustratorShape *shape = illustrator_->getShape(toolbar_->getAnchorObject().toStdString());

    if (shape == 0) return;

    CQIllustratorAlignToolbar::ObjectEdgeType edgeType =
      toolbar_->getAnchorObjectEdgeType();

    abbox = shape->getFlatBBox();

    if      (edgeType == CQIllustratorAlignToolbar::ObjectEdgeType::LEFT_BOTTOM)
      abbox = CBBox2D(abbox.getLL(), abbox.getLR());
    else if (edgeType == CQIllustratorAlignToolbar::ObjectEdgeType::RIGHT_TOP)
      abbox = CBBox2D(abbox.getUR(), abbox.getUR());
    else if (edgeType == CQIllustratorAlignToolbar::ObjectEdgeType::MIDDLE)
      abbox = CBBox2D(abbox.getCenter(), abbox.getCenter());

    bbbox = abbox;
  }
  else if (anchorMode == CQIllustratorAlignToolbar::AnchorMode::POSITION) {
    QPointF pos = toolbar_->getAnchorPosition();

    abbox = CBBox2D(CQUtil::fromQPoint(pos), CQUtil::fromQPoint(pos));

    CQIllustratorSelectedShapes::iterator ps1 = selection->begin(), ps2 = selection->end();

    for ( ; ps1 != ps2; ++ps1) {
      CQIllustratorShape *shape = (*ps1).getShape();

      const CBBox2D &bbox = shape->getFlatBBox();

      bbbox += bbox;
    }
  }
  else
    return;

  // align

  double offset = toolbar_->getOffset();

  if (commit) {
    illustrator_->startUndoGroup("Align");

    CQIllustratorSelectedShapes::iterator ps1 = selection->begin(), ps2 = selection->end();

    for ( ; ps1 != ps2; ++ps1) {
      CQIllustratorShape *shape = (*ps1).getShape();

      if (shape->getFixed()) continue;

      const CBBox2D &bbox = shape->getFlatBBox();

      double dx = 0.0, dy = 0.0;

      if (shape != ashape) {
        if      (side == CQIllustrator::ALIGN_LEFT      ) dx = abbox.getXMin() - bbox.getXMin();
        else if (side == CQIllustrator::ALIGN_BOTTOM    ) dy = abbox.getYMin() - bbox.getYMin();
        else if (side == CQIllustrator::ALIGN_RIGHT     ) dx = abbox.getXMax() - bbox.getXMax();
        else if (side == CQIllustrator::ALIGN_TOP       ) dy = abbox.getYMax() - bbox.getYMax();
        else if (side == CQIllustrator::ALIGN_HORIZONTAL) dy = abbox.getYMid() - bbox.getYMid();
        else if (side == CQIllustrator::ALIGN_VERTICAL  ) dx = abbox.getXMid() - bbox.getXMid();
      }

      if      (side == CQIllustrator::ALIGN_LEFT      ) dx += offset;
      else if (side == CQIllustrator::ALIGN_BOTTOM    ) dy += offset;
      else if (side == CQIllustrator::ALIGN_RIGHT     ) dx -= offset;
      else if (side == CQIllustrator::ALIGN_TOP       ) dy -= offset;
      else if (side == CQIllustrator::ALIGN_HORIZONTAL) dy += offset;
      else if (side == CQIllustrator::ALIGN_VERTICAL  ) dx += offset;

      shape->moveBy(CPoint2D(dx, dy));
    }

    illustrator_->endUndoGroup();

    illustrator_->setDimmed(false);

    illustrator_->clearPreviewObjects();

    illustrator_->redraw();
  }
  else {
    illustrator_->clearPreviewObjects();

    CQIllustratorSelectedShapes::iterator ps1 = selection->begin(), ps2 = selection->end();

    for ( ; ps1 != ps2; ++ps1) {
      CQIllustratorShape *shape = (*ps1).getShape();

      if (shape->getFixed()) continue;

      const CBBox2D &bbox = shape->getFlatBBox();

      double dx = 0.0, dy = 0.0;

      if (shape != ashape) {
        if      (side == CQIllustrator::ALIGN_LEFT      ) dx = abbox.getXMin() - bbox.getXMin();
        else if (side == CQIllustrator::ALIGN_BOTTOM    ) dy = abbox.getYMin() - bbox.getYMin();
        else if (side == CQIllustrator::ALIGN_RIGHT     ) dx = abbox.getXMax() - bbox.getXMax();
        else if (side == CQIllustrator::ALIGN_TOP       ) dy = abbox.getYMax() - bbox.getYMax();
        else if (side == CQIllustrator::ALIGN_HORIZONTAL) dy = abbox.getYMid() - bbox.getYMid();
        else if (side == CQIllustrator::ALIGN_VERTICAL  ) dx = abbox.getXMid() - bbox.getXMid();
      }

      if      (side == CQIllustrator::ALIGN_LEFT      ) dx += offset;
      else if (side == CQIllustrator::ALIGN_BOTTOM    ) dy += offset;
      else if (side == CQIllustrator::ALIGN_RIGHT     ) dx -= offset;
      else if (side == CQIllustrator::ALIGN_TOP       ) dy -= offset;
      else if (side == CQIllustrator::ALIGN_HORIZONTAL) dy += offset;
      else if (side == CQIllustrator::ALIGN_VERTICAL  ) dx += offset;

      illustrator_->addPreviewObject(new CQIllustrator::PreviewShape(shape, CPoint2D(dx, dy)));
    }

    double x1 = 0.0, y1 = 0.0, x2 = 0.0, y2 = 0.0;

    if      (side == CQIllustrator::ALIGN_LEFT || side == CQIllustrator::ALIGN_RIGHT) {
      x1 = abbox.getXMin();
      x2 = abbox.getXMax();

      y1 = bbbox.getYMin();
      y2 = bbbox.getYMax();
    }
    else if (side == CQIllustrator::ALIGN_BOTTOM || side == CQIllustrator::ALIGN_TOP) {
      y1 = abbox.getYMin();
      y2 = abbox.getYMax();

      x1 = bbbox.getXMin();
      x2 = bbbox.getXMax();
    }
    else if (side == CQIllustrator::ALIGN_HORIZONTAL) {
      x1 = bbbox.getXMin();
      x2 = bbbox.getXMax();

      y1 = abbox.getYMid();
      y2 = y2;
    }
    else if (side == CQIllustrator::ALIGN_VERTICAL) {
      y1 = bbbox.getYMin();
      y2 = bbbox.getYMax();

      x1 = abbox.getXMid();
      x2 = x1;
    }

    double dx = (x2 - x1)/8;
    double dy = (y2 - y1)/8;

    if      (side == CQIllustrator::ALIGN_LEFT      )
      illustrator_->addPreviewObject(
        new CQIllustrator::PreviewLine(CPoint2D(x1, y1 - dy), CPoint2D(x1, y2 + dy)));
    else if (side == CQIllustrator::ALIGN_BOTTOM    )
      illustrator_->addPreviewObject(
        new CQIllustrator::PreviewLine(CPoint2D(x1 - dx, y1), CPoint2D(x2 + dx, y1)));
    else if (side == CQIllustrator::ALIGN_RIGHT     )
      illustrator_->addPreviewObject(
        new CQIllustrator::PreviewLine(CPoint2D(x2, y1 - dy), CPoint2D(x2, y2 + dy)));
    else if (side == CQIllustrator::ALIGN_TOP       )
      illustrator_->addPreviewObject(
        new CQIllustrator::PreviewLine(CPoint2D(x1 - dx, y2), CPoint2D(x2 + dx, y2)));
    else if (side == CQIllustrator::ALIGN_HORIZONTAL)
      illustrator_->addPreviewObject(
        new CQIllustrator::PreviewLine(CPoint2D(x1 - dx, y1), CPoint2D(x2 + dx, y1)));
    else if (side == CQIllustrator::ALIGN_VERTICAL  )
      illustrator_->addPreviewObject(
        new CQIllustrator::PreviewLine(CPoint2D(x1, y1 - dy), CPoint2D(x1, y2 + dy)));

    illustrator_->redrawOverlay();
  }
}
Ejemplo n.º 5
0
void
CSVGBuffer::
drawImage(const CBBox2D &bbox, CImagePtr image)
{
  renderer_->drawImage(bbox.getLL(), image);
}