summaryrefslogtreecommitdiffstats
path: root/qtruby/rubylib/examples/qt-examples/tooltip/tooltip.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/tooltip/tooltip.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/tooltip/tooltip.rb')
-rw-r--r--qtruby/rubylib/examples/qt-examples/tooltip/tooltip.rb95
1 files changed, 95 insertions, 0 deletions
diff --git a/qtruby/rubylib/examples/qt-examples/tooltip/tooltip.rb b/qtruby/rubylib/examples/qt-examples/tooltip/tooltip.rb
new file mode 100644
index 00000000..181816da
--- /dev/null
+++ b/qtruby/rubylib/examples/qt-examples/tooltip/tooltip.rb
@@ -0,0 +1,95 @@
+require 'Qt'
+
+class DynamicTip < Qt::ToolTip
+ def initialize(p)
+ super(p)
+ end
+
+ def maybeTip(p)
+ if !parentWidget.inherits('TellMe')
+ return
+ end
+
+ r = parentWidget.tip(p)
+ if !r.isValid
+ return
+ end
+
+ s = 'position: ' + r.center.x.to_s + ', ' + r.center.y.to_s
+ tip(r,s)
+ end
+end
+
+class TellMe < Qt::Widget
+
+ def initialize
+ super
+
+ setMinimumSize(30, 30)
+
+ @r1 = randomRect
+ @r2 = randomRect
+ @r3 = randomRect
+
+ @t = DynamicTip.new(self)
+
+ Qt::ToolTip.add(self, @r3, 'this color is called red') #TT says this is helpful, I'm not so sure
+ end
+
+ def tip(point)
+ if (@r1.contains(point))
+ @r1
+ elsif (@r2.contains(point))
+ @r2
+ else
+ Qt::Rect.new(0,0, -1, -1)
+ end
+ end
+
+ def paintEvent(e)
+ p = Qt::Painter.new(self)
+
+ if (e.rect.intersects(@r1))
+ p.setBrush(Qt::blue)
+ p.drawRect(@r1)
+ end
+
+ if (e.rect.intersects(@r2))
+ p.setBrush(Qt::blue)
+ p.drawRect(@r2)
+ end
+
+ if (e.rect.intersects(@r3))
+ p.setBrush(Qt::red)
+ p.drawRect(@r3)
+ end
+
+ p.end
+ end
+
+ def mousePressEvent (e)
+ if (@r1.contains(e.pos))
+ @r1 = randomRect
+ end
+
+ if (@r2.contains(e.pos))
+ @r2 = randomRect
+ end
+
+ repaint
+ end
+
+ def resizeEvent(e)
+ unless rect.contains(@r1)
+ @r1 = randomRect
+ end
+
+ unless rect.contains(@r2)
+ @r2 = randomRect
+ end
+ end
+
+ def randomRect
+ Qt::Rect.new(rand(width - 20), rand(height - 20), 20, 20)
+ end
+end