diff options
author | Timothy Pearson <[email protected]> | 2012-01-01 18:29:30 -0600 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2012-01-01 18:29:30 -0600 |
commit | b2af005db21bd8fd068cb79b2ae700953128af2c (patch) | |
tree | abd0ed633726bf0bbecb57d30e92836c31e02695 /PerlTQt/examples/dclock | |
parent | c1b9383f2032d82db5eb8918dca885e37a901dde (diff) | |
download | libtqt-perl-b2af005db21bd8fd068cb79b2ae700953128af2c.tar.gz libtqt-perl-b2af005db21bd8fd068cb79b2ae700953128af2c.zip |
Move PerlQt
Diffstat (limited to 'PerlTQt/examples/dclock')
-rw-r--r-- | PerlTQt/examples/dclock/DigitalClock.pm | 88 | ||||
-rw-r--r-- | PerlTQt/examples/dclock/dclock.pl | 12 |
2 files changed, 100 insertions, 0 deletions
diff --git a/PerlTQt/examples/dclock/DigitalClock.pm b/PerlTQt/examples/dclock/DigitalClock.pm new file mode 100644 index 0000000..2d25428 --- /dev/null +++ b/PerlTQt/examples/dclock/DigitalClock.pm @@ -0,0 +1,88 @@ +package DigitalClock; +use strict; +use TQt; +use TQt::isa qw(TQt::LCDNumber); +use TQt::slots + stopDate => [], + showTime => []; +use TQt::attributes qw( + showingColon + normalTimer + showDateTimer +); + +# +# Constructs a DigitalClock widget +# + +sub NEW { + shift->SUPER::NEW(@_); + showingColon = 0; + setFrameStyle(&Panel | &Raised); + setLineWidth(2); + showTime(); + normalTimer = startTimer(500); + showDateTimer = -1; +} + +# +# Handles timer events and 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 +# + +sub timerEvent { + my $e = shift; + if($e->timerId == showDateTimer) { # stop showing date + stopDate(); + } elsif(showDateTimer == -1) { # normal timer + showTime(); + } +} + +# +# Enters date mode when the left mouse button is pressed +# + +sub mousePressEvent { + my $e = shift; + showDate() if $e->button == &LeftButton; +} + +# +# Shows the durrent date in the internal lcd widget. +# Fires a timer to stop showing the date. +# + +sub showDate { + return if showDateTimer != -1; # already showing date + my $date = TQt::Date::currentDate(); + my $s = sprintf("%2d %2d", $date->month, $date->day); + display($s); # sets the LCD number/text + showDateTimer = startTimer(2000); # keep this state for 2 secs +} + +# +# Stops showing the date. +# + +sub stopDate { + killTimer(showDateTimer); + showDateTimer = -1; + showTime(); +} + +# +# Shows the current time in the internal lcd widget. +# + +sub showTime { + showingColon = !showingColon; + my $s = substr(TQt::Time::currentTime()->toString, 0, 5); + $s =~ s/^0/ /; + $s =~ s/:/ / unless showingColon; + display($s); +} + +1; + diff --git a/PerlTQt/examples/dclock/dclock.pl b/PerlTQt/examples/dclock/dclock.pl new file mode 100644 index 0000000..57c02bd --- /dev/null +++ b/PerlTQt/examples/dclock/dclock.pl @@ -0,0 +1,12 @@ +#!/usr/bin/perl -w +use strict; +use TQt; +use DigitalClock; + +my $a = TQt::Application(\@ARGV); +my $clock = DigitalClock; +$clock->resize(170, 80); +$a->setMainWidget($clock); +$clock->setCaption("PerlTQt Example - Digital Clock"); +$clock->show; +exit $a->exec; |