summaryrefslogtreecommitdiffstats
path: root/qtruby/rubylib/examples/qt-examples/dclock
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/dclock
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/dclock')
-rw-r--r--qtruby/rubylib/examples/qt-examples/dclock/dclock.rb67
-rwxr-xr-xqtruby/rubylib/examples/qt-examples/dclock/main.rb12
2 files changed, 79 insertions, 0 deletions
diff --git a/qtruby/rubylib/examples/qt-examples/dclock/dclock.rb b/qtruby/rubylib/examples/qt-examples/dclock/dclock.rb
new file mode 100644
index 00000000..6ac52c4c
--- /dev/null
+++ b/qtruby/rubylib/examples/qt-examples/dclock/dclock.rb
@@ -0,0 +1,67 @@
+require 'Qt'
+
+class DigitalClock < Qt::LCDNumber
+
+ slots 'stopDate()', 'showTime()'
+
+ # Constructs a DigitalClock widget
+ def initialize
+ super
+
+ @showingColon = false
+ setFrameStyle(Qt::Frame.Panel | Qt::Frame.Raised)
+ setLineWidth(2) # set frame line width
+ showTime # display the current time
+ @normalTimer = startTimer(500) # 1/2 second timer events
+ @showDateTimer = -1 # not showingdate
+ end
+
+ # Handles timer events for the digital clock widget.
+ # There are two different timers; one timer for updating the clock
+ # and another one for switching back from date mode to time mode.
+ def timerEvent (e)
+ if (e.timerId == @showDateTimer) # stop showing date
+ stopDate
+ else # normal timer
+ if (@showDateTimer == -1) # not showing date
+ showTime()
+ end
+ end
+ end
+
+ # Enters date mode when the left mouse button is pressed.
+ def mousePressEvent (e)
+ if (e.button == Qt::MouseEvent.LeftButton) # left button pressed
+ showDate
+ end
+ end
+
+ def stopDate
+ killTimer(@showDateTimer)
+ @showDateTimer = -1
+ showTime
+ end
+
+ def showTime
+ @showingColon = !@showingColon # toggle/blink colon
+ s = Qt::Time.currentTime.toString[0..4]
+ if (!@showingColon)
+ s[2] = ' '
+ end
+ if (s[0] == '0')
+ s[0] = ' '
+ end
+ display(s) # set LCD number/text
+ end
+
+ def showDate
+ if (@showDateTimer != -1) # already showing date
+ return
+ end
+ date = Qt::Date.currentDate
+ s = sprintf('%2d %2d', date.month, date.day)
+ display(s) # sets the LCD number/text
+ @showDateTimer = startTimer(2000) # keep this state for 2 secs
+ end
+
+end
diff --git a/qtruby/rubylib/examples/qt-examples/dclock/main.rb b/qtruby/rubylib/examples/qt-examples/dclock/main.rb
new file mode 100755
index 00000000..c76ae55d
--- /dev/null
+++ b/qtruby/rubylib/examples/qt-examples/dclock/main.rb
@@ -0,0 +1,12 @@
+#!/usr/bin/env ruby
+
+require 'Qt'
+require 'dclock'
+
+a = Qt::Application.new(ARGV)
+clock = DigitalClock.new
+clock.resize(170,80)
+a.setMainWidget(clock)
+clock.setCaption('QtRuby Example - Digital Clock')
+clock.show
+a.exec