Ejemplo n.º 1
0
void PaintBrush::mouseDown(const WMouseEvent& e)
{
    Coordinates c = e.widget();
    if (interactionCount_ % 2 == 0) {
        path_ = WPainterPath(WPointF(c.x, c.y));
        Vertex v;
        v.id = interactionCount_;
        v.x = c.x;
        v.y = c.y;
        vertexList_.push_back(v);
        interactionCount_++;
        path_.addRect(c.x, c.y, 1, 1);
        update(PaintUpdate);
    } else {
        path_.lineTo(c.x, c.y);
        Vertex v;
        v.id = interactionCount_;
        v.x = c.x;
        v.y = c.y;
        vertexList_.push_back(v);
        Edge e;
        e.v1 = v.id - 1;
        e.v2 = v.id;
        e.speed = currentSpeed_;
        edgeList_.push_back(e);
        interactionCount_++;
        path_.addRect(c.x, c.y, 1, 1);
        actions_.push_back(path_);
        update(PaintUpdate);
    }
}
Ejemplo n.º 2
0
void PaintBrush::paintEvent(WPaintDevice *paintDevice)
{
    WPainter painter(paintDevice);
    painter.setRenderHint(WPainter::Antialiasing);

    WPen pen;
    pen.setWidth(3);
    pen.setColor(color_);
    painter.setPen(pen);
    
    if (interactionCount_ == 0 && !actions_.empty()) {
        drawActions(painter);
        interactionCount_ = vertexList_.size();
    }
    
    if (!undo_)
    {
        painter.drawPath(path_);
    }
    else
    {
        drawActions(painter);
        undo_ = false;
        update(PaintUpdate);
    }
    path_ = WPainterPath(path_.currentPosition());
}
Ejemplo n.º 3
0
void PaintBrush::loadImage(const Node& root)
{
    update();
    interactionCount_ = 0;
    actions_.clear();
    vertexList_.clear();
    edgeList_.clear();
    std::list< Node > children = root.children();
    std::list< Node >::iterator it;
    for (it = children.begin(); it != children.end(); ++it)
    {
        if (it->name() == "vertex") vertexList_.push_back(extractVertex(it->children()));
        if (it->name() == "edge") edgeList_.push_back(extractEdge(it->children()));
    }

    // now iterate the edges and update the image.
    std::list< Edge >::iterator eit;
    for (eit = edgeList_.begin(); eit != edgeList_.end(); ++eit)
    {
        Vertex v1 = lookup(eit->v1);
        path_ = WPainterPath(WPointF(v1.x, v1.y));
        path_.addRect(v1.x, v1.y, 1, 1);
        Vertex v2 = lookup(eit->v2);
        path_.lineTo(v2.x, v2.y);
        path_.addRect(v2.x, v2.y, 1, 1);
        actions_.push_back(path_);
    }
    update(PaintUpdate);
}
Ejemplo n.º 4
0
void PaintBrush::paintEvent(WPaintDevice *paintDevice)
{
  WPainter painter(paintDevice);
  painter.setRenderHint(WPainter::Antialiasing);
  
  WPen pen;
  pen.setWidth(3);
  pen.setColor(color_);
  pen.setCapStyle(FlatCap);
  pen.setJoinStyle(MiterJoin);
  painter.setPen(pen);
  painter.drawPath(path_);

  path_ = WPainterPath(path_.currentPosition());
}
Ejemplo n.º 5
0
void PaintBrush::touchStart(const WTouchEvent& e)
{
  Coordinates c = e.touches()[0].widget();
  path_ = WPainterPath(WPointF(c.x, c.y));
}
Ejemplo n.º 6
0
void PaintBrush::mouseDown(const WMouseEvent& e)
{
  Coordinates c = e.widget();
  path_ = WPainterPath(WPointF(c.x, c.y));
}