Exemplo n.º 1
0
void Renderer::drawBar(const cpShape* shape) {
  const auto p1 = cpSegmentShapeGetA(shape);
  const auto p2 = cpSegmentShapeGetB(shape);
  const auto radius = static_cast<float>(cpSegmentShapeGetRadius(shape));
  auto rect = RoundedBar(radius);
  rect.setOutlineColor(sf::Color::Green);
  rect.setOutlineThickness(1.0f);
  rect.setFillColor(sf::Color::Transparent);
  const auto sfp1 = Utils::toSfv(p1, mTargetSize);
  const auto sfp2 = Utils::toSfv(p2, mTargetSize);
  const auto len = static_cast<float>(cpvdist(p1, p2));

  if (p1.x == p2.x) {
    rect.setLength(len);
    auto y = std::min(sfp1.y, sfp2.y);
    rect.setRotation(90);
    rect.setPosition(sfp1.x, y + len / 2 - radius);
    rect.adjustOrigin();
  } else if (p1.y == p2.y) {
    rect.setLength(len);
    auto x = std::min(sfp1.x, sfp2.x);
    rect.setPosition(x + len / 2 - radius, sfp1.y);
    rect.adjustOrigin();
  }
  {
    for (auto& target : mTargets) {
      auto view = target->getView();
      auto center = view.getCenter();
      auto pieceW = view.getSize().x * 1.0f;
      auto pieceH = view.getSize().y * 1.0f;
      auto x = center.x - pieceW / 2.0f;
      auto y = center.y - pieceH / 2.0f;
      auto vRect = sf::FloatRect(x, y, pieceW, pieceH);
      if (vRect.intersects(rect.getGlobalBounds())) {
        target->draw(rect);
      }
    }
  }
}
Exemplo n.º 2
0
KChartCanvas::KChartCanvas( KChartView *view, KChartPart *parent )
    : QWidget(),
      KoCanvasBase( parent ),
      m_origin( 0, 0 ),
      m_documentOffset( 0, 0 )
{
    m_part = parent;
    m_view = view;
    m_shapeManager = new KoShapeManager( this );
    //m_shapeManager->add( m_part->shape() );
    m_toolProxy = new KoToolProxy( this );

    setBackgroundRole( QPalette::Base );
    setAutoFillBackground( true );
    setMouseTracking( true );
    setFocusPolicy( Qt::ClickFocus ); // allow to receive keyboard input
    adjustOrigin();
    setAttribute( Qt::WA_InputMethodEnabled, true );

    m_documentRect = m_part->chart()->boundingRect();

    connect(m_shapeManager, SIGNAL( selectionChanged() ), this, SLOT( adjustOrigin() ) );
}
Exemplo n.º 3
0
void KChartCanvas::addCommand( QUndoCommand *command )
{
    m_part->KoDocument::addCommand( command );
    adjustOrigin();
}
Exemplo n.º 4
0
void KChartCanvas::resizeEvent( QResizeEvent *e )
{
    adjustOrigin();
}