You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
1.7 KiB
89 lines
1.7 KiB
13 years ago
|
package DigitalClock;
|
||
|
use strict;
|
||
13 years ago
|
use TQt;
|
||
|
use TQt::isa qw(TQt::LCDNumber);
|
||
|
use TQt::slots
|
||
13 years ago
|
stopDate => [],
|
||
|
showTime => [];
|
||
13 years ago
|
use TQt::attributes qw(
|
||
13 years ago
|
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
|
||
13 years ago
|
my $date = TQt::Date::currentDate();
|
||
13 years ago
|
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;
|
||
13 years ago
|
my $s = substr(TQt::Time::currentTime()->toString, 0, 5);
|
||
13 years ago
|
$s =~ s/^0/ /;
|
||
|
$s =~ s/:/ / unless showingColon;
|
||
|
display($s);
|
||
|
}
|
||
|
|
||
|
1;
|
||
|
|