diff options
Diffstat (limited to 'qtruby/rubylib/examples/qt-examples/chart/canvasview.rb')
-rw-r--r-- | qtruby/rubylib/examples/qt-examples/chart/canvasview.rb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/qtruby/rubylib/examples/qt-examples/chart/canvasview.rb b/qtruby/rubylib/examples/qt-examples/chart/canvasview.rb new file mode 100644 index 00000000..416b0de7 --- /dev/null +++ b/qtruby/rubylib/examples/qt-examples/chart/canvasview.rb @@ -0,0 +1,53 @@ +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 + + |