Class: Qt::GraphicsScene

Inherits:
Object show all
Defined in:
lib/roby/gui/relations_view/relations_canvas.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_arrow_brushObject (readonly)

Returns the value of attribute default_arrow_brush.



361
362
363
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 361

def default_arrow_brush
  @default_arrow_brush
end

#default_arrow_penObject (readonly)

Returns the value of attribute default_arrow_pen.



361
362
363
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 361

def default_arrow_pen
  @default_arrow_pen
end

Instance Method Details

#add_arrow(size, pen = nil, brush = nil) ⇒ Object



363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 363

def add_arrow(size, pen = nil, brush = nil)
    @default_arrow_pen   ||= Qt::Pen.new(ARROW_COLOR)
    @default_arrow_brush ||= Qt::Brush.new(ARROW_COLOR)

    @arrow_points ||= (1..4).map { Qt::PointF.new(0, 0) }
    @arrow_points[1].x = -size
    @arrow_points[1].y = size / 2
    @arrow_points[2].x = -size
    @arrow_points[2].y = -size / 2
    polygon = Qt::PolygonF.new(@arrow_points)
    @arrow_line ||= Qt::LineF.new(-1, 0, 0, 0)

    ending = add_polygon polygon, (pen || default_arrow_pen), (brush || default_arrow_brush)
    line   = add_line @arrow_line

    @arrow_id ||= 0
    id = (@arrow_id += 1)
    line.setData(0, Qt::Variant.new(id.to_s))
    ending.setData(0, Qt::Variant.new(id.to_s))

    line.parent_item = ending
    ending.singleton_class.class_eval do
        attr_accessor :line

        def pen=(pen)
            super
            line.pen = pen
        end
    end
    ending.line = line
    ending
end