use strict;
#............................................................. DigitalClock
package DigitalClock;
   use Qt;
   use Qt::isa qw(Qt::LCDNumber); # Klasse DigitalClock erbt Qt::LCDNumber
   use Qt::attributes qw( showingColon normalTimer showDateTimer );
   use Qt::slots
       stopDate => [];
       showTime => [];
   sub NEW { #..................................... Konstruktor
      shift->SUPER::NEW(@_[0..2]);
      setFrameStyle(&Qt::Frame::Panel | &Qt::Frame::Raised);
      setLineWidth(2);
      showTime();
      showingColon  = 0;
      normalTimer   = startTimer(500);
      showDateTimer = -1;
   }
   sub timerEvent { #............................... timerEvent
      my $e = shift;
      if ($e->timerId() == showDateTimer) {
         stopDate();
      } elsif (showDateTimer == -1) {
         showTime();
      }
   }
   sub mousePressEvent { #..................... mousePressEvent
      my $event = shift;
      if ($event->button() == &Qt::LeftButton) {
         showDate();
      }
   }
   sub showDate { #................................... showDate
      return unless showDateTimer == -1;
      my($day, $mon) = (localtime)[3, 4];
      display(sprintf('%2d.%2d', $day, $mon+1));
      showDateTimer = startTimer(2000);
   }
   sub stopDate { #................................... stopDate
      killTimer(showDateTimer);
      showDateTimer = -1;
      showTime();
   }
   sub showTime { #................................... showTime
      showingColon = !showingColon;
      my($sec, $min, $hour) = (localtime)[0, 1, 2];
      my $s = sprintf("%d %.2d %.2d", $hour, $min, $sec);
      if (showingColon) {
         $s =~ s/ /:/g;
      }
      display($s);
   }
