module Ui::PlanDisplay::GraphicsViewExtension

Module used to extend the Qt::GraphicsView widget to provide events on click, and zoom with Ctrl + Wheel

Attributes

plan_display[RW]

The underlying PlanDisplay object

Public Instance Methods

mousePressEvent(event) click to toggle source

Handler that emits the selectedObject signal on the underlying PlanDisplay instance if the user clicks on a SVG item that represents a registered plan object

# File lib/orocos/roby/gui/plan_display.rb, line 22
def mousePressEvent(event)
    items = self.items(event.pos)
    items = items.find_all do |i|
        i.respond_to?(:real_object) &&
            i.real_object
    end
    if (sel = items.first) && sel.real_object
        emit plan_display.
            selectedObject(Qt::Variant.fromValue(sel.real_object), event.globalPos)
    end
    event.accept
end
wheelEvent(event) click to toggle source

Handler that changes the current_scaling factor (and updates the view) on Ctrl + Wheel events

Calls superclass method
# File lib/orocos/roby/gui/plan_display.rb, line 37
def wheelEvent(event)
    if event.modifiers != Qt::ControlModifier
        return super
    end

    # See documentation of wheelEvent
    degrees = event.delta / 8.0
    num_steps = degrees / 60.0

    old = self.current_scaling
    new = old + num_steps
    if new.abs < 1
        if old > 0
            @current_scaling = -1
        else
            @current_scaling = 1
        end
    else
        @current_scaling = new
    end

    current_scaling = (self.current_scaling * 10).round / 10.0
    scale_factor =
        if current_scaling > 0
            current_scaling
        else
            1.0 / current_scaling.abs
        end

    self.transform = Qt::Transform.from_scale(scale_factor, scale_factor)

    event.accept
end