You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tdebindings/qtruby/rubylib/examples/qt-examples/chart/canvasview.rb

54 lines
1.3 KiB

class CanvasView < Qt::CanvasView
def initialize(canvas, elements, parent = nil, name = "canvas view", f = 0)
super(canvas, parent, name, f)
@elements = elements
@movingItem = nil
end
def contentsContextMenuEvent( e )
parent().optionsMenu.exec( Qt::Cursor.pos() )
end
def viewportResizeEvent( e )
canvas().resize( e.size().width(), e.size().height() )
parent().drawElements()
end
def contentsMousePressEvent( e )
list = canvas().collisions( e.pos() )
list.each do |it|
if it.rtti() == CanvasText::CANVAS_TEXT
@movingItem = it
@pos = e.pos()
return
end
end
@movingItem = nil
end
def contentsMouseMoveEvent( e )
if @movingItem
offset = e.pos() - @pos
@movingItem.moveBy( offset.x(), offset.y() )
@pos = e.pos()
form = parent()
form.changed = true
chartType = form.chartType()
item = @movingItem
i = item.index()
@elements[i].setProX( chartType, item.x() / canvas().width() )
@elements[i].setProY( chartType, item.y() / canvas().height() )
canvas().update()
end
end
end