summaryrefslogtreecommitdiffstats
path: root/qtruby/rubylib/examples/canvastest/canvastest.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/canvastest/canvastest.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/canvastest/canvastest.rb')
-rw-r--r--qtruby/rubylib/examples/canvastest/canvastest.rb75
1 files changed, 75 insertions, 0 deletions
diff --git a/qtruby/rubylib/examples/canvastest/canvastest.rb b/qtruby/rubylib/examples/canvastest/canvastest.rb
new file mode 100644
index 00000000..4187d91d
--- /dev/null
+++ b/qtruby/rubylib/examples/canvastest/canvastest.rb
@@ -0,0 +1,75 @@
+#!/usr/bin/env ruby -w
+
+require 'Qt'
+require 'rexml/document'
+
+require '../base/kicons.rb'
+require '../base/rui.rb'
+
+class MyCanvasView < Qt::CanvasView
+ def initialize(canvas, parent)
+ @canvas = canvas
+ super(canvas, parent)
+ end
+ def contentsMousePressEvent(e)
+ super
+ list = canvas.collisions(e.pos)
+ return if list.empty?
+ c = list.first
+ return if c.rtti != Qt::CanvasItem::Rtti_Rectangle
+ c.hide
+ @canvas.update
+ end
+end
+
+class MyWidget < Qt::MainWindow
+ slots 'new()', 'open()', 'save_as()'
+ def make_rect
+ rect = Qt::CanvasRectangle.new(rand(@canvas.width()), rand(@canvas.height()),
+ @canvas.width / 5, @canvas.width / 5, @canvas)
+ z = rand(256)
+ color = Qt::Color.new(z,z,z)
+ rect.setBrush(Qt::Brush.new(color))
+ color = Qt::Color.new(rand(32)*8, rand(32)*8, rand(32)*8)
+ rect.setPen(Qt::Pen.new(color, 6))
+ rect.setZ(z)
+ rect.show
+ @rects << rect
+ end
+ def initialize()
+ super
+
+ fileTools = Qt::ToolBar.new(self, "file operations")
+ fileMenu = Qt::PopupMenu.new(self)
+
+ actions = [
+ RAction.new("&New", Icons::FILE_NEW, self, SLOT('new()'), [fileTools, fileMenu]),
+ RAction.new("&Open...", Icons::FILE_OPEN, self, SLOT('open()'), [fileTools, fileMenu]),
+ @save = RAction.new("Save &As...", Icons::FILE_SAVE_AS, self, SLOT('save_as()'), [fileTools, fileMenu]),
+ RSeperator.new([fileMenu]),
+ RAction.new("E&xit", Icons::EXIT, $qApp, SLOT('quit()'), [fileMenu])
+ ]
+ build_actions(actions)
+
+ menubar = Qt::MenuBar.new(self)
+ menubar.insertItem("&File", fileMenu)
+
+ @canvas = Qt::Canvas.new(640, 480)
+
+ @rects = []
+ 5.times { make_rect }
+
+ @canvas_view = MyCanvasView.new(@canvas, self)
+ self.setCentralWidget(@canvas_view)
+ @canvas.update
+ end
+end
+
+a = Qt::Application.new(ARGV)
+
+w = MyWidget.new
+w.show
+
+a.setMainWidget(w)
+a.exec()
+exit