summaryrefslogtreecommitdiffstats
path: root/qtruby/rubylib/examples/qt-examples/chart/canvasview.rb
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit90825e2392b2d70e43c7a25b8a3752299a933894 (patch)
treee33aa27f02b74604afbfd0ea4f1cfca8833d882a /qtruby/rubylib/examples/qt-examples/chart/canvasview.rb
downloadtdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.tar.gz
tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebindings@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'qtruby/rubylib/examples/qt-examples/chart/canvasview.rb')
-rw-r--r--qtruby/rubylib/examples/qt-examples/chart/canvasview.rb53
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
+
+