diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 90825e2392b2d70e43c7a25b8a3752299a933894 (patch) | |
tree | e33aa27f02b74604afbfd0ea4f1cfca8833d882a /qtruby/rubylib/examples/qt-examples/forever | |
download | tdebindings-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/forever')
-rwxr-xr-x | qtruby/rubylib/examples/qt-examples/forever/forever.rb | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/qtruby/rubylib/examples/qt-examples/forever/forever.rb b/qtruby/rubylib/examples/qt-examples/forever/forever.rb new file mode 100755 index 00000000..46849784 --- /dev/null +++ b/qtruby/rubylib/examples/qt-examples/forever/forever.rb @@ -0,0 +1,84 @@ +#!/usr/bin/env ruby -w + +require 'Qt' + +# +# Forever - a widget that draws rectangles forever. +# + +class Forever < Qt::Widget + + NUM_COLORS = 120 + # + # Constructs a Forever widget. + # + + slots 'updateCaption()' + + def initialize(*k) + super(nil) + @colors = [] + 0.upto(NUM_COLORS-1) do |a| + @colors[a] = Qt::Color.new( rand(255), + rand(255), + rand(255) ) + end + @rectangles = 0 + startTimer( 0 ) # run continuous timer + counter = Qt::Timer.new( self ) + connect( counter, SIGNAL("timeout()"), + self, SLOT("updateCaption()") ) + counter.start( 1000 ) + end + + + def updateCaption() + s = "Qt Example - Forever - " + @rectangles.to_s + " rectangles/second" + @rectangles = 0 + self.caption = s + end + + + # + # Handles paint events for the Forever widget. + # + + def paintEvent( e ) + paint = Qt::Painter.new( self ) # painter object + w = width() + h = height() + if w <= 0 || h <= 0 then + return + end + paint.setPen( NoPen ) # do not draw outline + paint.setBrush( @colors[rand(NUM_COLORS)]) # set random brush color + + p1 = Qt::Point.new( rand(w), rand(h)) # p1 = top left + p2 = Qt::Point.new( rand(w), rand(h)) # p2 = bottom right + + r = Qt::Rect.new( p1, p2 ) + paint.drawRect( r ) # draw filled rectangle + paint.end() + end + + # + # Handles timer events for the Forever widget. + # + + def timerEvent( e ) + 0.upto(99) do |i| + repaint( false ) # repaint, don't erase + end + @rectangles += 100 + end + + +end + +a = Qt::Application.new(ARGV) +always = Forever.new +always.resize( 400, 250 ) # start up with size 400x250 +a.mainWidget = always # set as main widget +always.caption = "QtRuby Example - Forever" +always.show +a.exec |