From 90825e2392b2d70e43c7a25b8a3752299a933894 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: 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 --- .../rubylib/examples/qt-examples/dclock/dclock.rb | 67 ++++++++++++++++++++++ qtruby/rubylib/examples/qt-examples/dclock/main.rb | 12 ++++ 2 files changed, 79 insertions(+) create mode 100644 qtruby/rubylib/examples/qt-examples/dclock/dclock.rb create mode 100755 qtruby/rubylib/examples/qt-examples/dclock/main.rb (limited to 'qtruby/rubylib/examples/qt-examples/dclock') 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 -- cgit v1.2.1