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.



323
324
325
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 323

def default_arrow_brush
  @default_arrow_brush
end

#default_arrow_penObject (readonly)

Returns the value of attribute default_arrow_pen.



322
323
324
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 322

def default_arrow_pen
  @default_arrow_pen
end

Instance Method Details

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



324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 324

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