summaryrefslogtreecommitdiffstats
path: root/examples/dclock
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-11-08 12:31:36 -0600
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-11-08 12:31:36 -0600
commitd796c9dd933ab96ec83b9a634feedd5d32e1ba3f (patch)
tree6e3dcca4f77e20ec8966c666aac7c35bd4704053 /examples/dclock
downloadtqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.tar.gz
tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.zip
Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731
Diffstat (limited to 'examples/dclock')
-rw-r--r--examples/dclock/README5
-rw-r--r--examples/dclock/dclock.cpp97
-rw-r--r--examples/dclock/dclock.doc29
-rw-r--r--examples/dclock/dclock.h39
-rw-r--r--examples/dclock/dclock.pro11
-rw-r--r--examples/dclock/main.cpp23
6 files changed, 204 insertions, 0 deletions
diff --git a/examples/dclock/README b/examples/dclock/README
new file mode 100644
index 000000000..dfa58402f
--- /dev/null
+++ b/examples/dclock/README
@@ -0,0 +1,5 @@
+The dclock program displays a digital LCD clock and can switch
+between time and date.
+
+See also the aclock sample that displays an analog clock.
+
diff --git a/examples/dclock/dclock.cpp b/examples/dclock/dclock.cpp
new file mode 100644
index 000000000..be7cc8539
--- /dev/null
+++ b/examples/dclock/dclock.cpp
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for TQt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include "dclock.h"
+#include <qdatetime.h>
+
+
+//
+// Constructs a DigitalClock widget with a parent and a name.
+//
+
+DigitalClock::DigitalClock( TQWidget *parent, const char *name )
+ : TQLCDNumber( parent, name )
+{
+ showingColon = FALSE;
+ setFrameStyle( TQFrame::Panel | TQFrame::Raised );
+ setLineWidth( 2 ); // set frame line width
+ showTime(); // display the current time
+ normalTimer = startTimer( 500 ); // 1/2 second timer events
+ showDateTimer = -1; // not showing date
+}
+
+
+//
+// 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.
+//
+
+void DigitalClock::timerEvent( TQTimerEvent *e )
+{
+ if ( e->timerId() == showDateTimer ) // stop showing date
+ stopDate();
+ else { // normal timer
+ if ( showDateTimer == -1 ) // not showing date
+ showTime();
+ }
+}
+
+//
+// Enters date mode when the left mouse button is pressed.
+//
+
+void DigitalClock::mousePressEvent( TQMouseEvent *e )
+{
+ if ( e->button() == TQMouseEvent::LeftButton ) // left button pressed
+ showDate();
+}
+
+
+//
+// Shows the current date in the internal lcd widget.
+// Fires a timer to stop showing the date.
+//
+
+void DigitalClock::showDate()
+{
+ if ( showDateTimer != -1 ) // already showing date
+ return;
+ TQDate date = TQDate::currentDate();
+ TQString s;
+ 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.
+//
+
+void DigitalClock::stopDate()
+{
+ killTimer( showDateTimer );
+ showDateTimer = -1;
+ showTime();
+}
+
+//
+// Shows the current time in the internal lcd widget.
+//
+
+void DigitalClock::showTime()
+{
+ showingColon = !showingColon; // toggle/blink colon
+ TQString s = TQTime::currentTime().toString().left(5);
+ if ( !showingColon )
+ s[2] = ' ';
+ if ( s[0] == '0' )
+ s[0] = ' ';
+ display( s ); // set LCD number/text
+}
diff --git a/examples/dclock/dclock.doc b/examples/dclock/dclock.doc
new file mode 100644
index 000000000..b341b6638
--- /dev/null
+++ b/examples/dclock/dclock.doc
@@ -0,0 +1,29 @@
+/*
+*/
+/*! \page dclock-example.html
+
+ \ingroup examples
+ \title Digital Clock
+
+ This example displays a digital LCD clock that can switch between time
+ and date.
+
+ <hr>
+
+ Header file:
+
+ \include dclock/dclock.h
+
+ <hr>
+
+ Implementation:
+
+ \include dclock/dclock.cpp
+
+ <hr>
+
+ Main:
+
+ \include dclock/main.cpp
+*/
+
diff --git a/examples/dclock/dclock.h b/examples/dclock/dclock.h
new file mode 100644
index 000000000..315c54221
--- /dev/null
+++ b/examples/dclock/dclock.h
@@ -0,0 +1,39 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for TQt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#ifndef DCLOCK_H
+#define DCLOCK_H
+
+#include <qlcdnumber.h>
+
+
+class DigitalClock : public TQLCDNumber // digital clock widget
+{
+ Q_OBJECT
+public:
+ DigitalClock( TQWidget *parent=0, const char *name=0 );
+
+protected: // event handlers
+ void timerEvent( TQTimerEvent * );
+ void mousePressEvent( TQMouseEvent * );
+
+private slots: // internal slots
+ void stopDate();
+ void showTime();
+
+private: // internal data
+ void showDate();
+
+ bool showingColon;
+ int normalTimer;
+ int showDateTimer;
+};
+
+
+#endif // DCLOCK_H
diff --git a/examples/dclock/dclock.pro b/examples/dclock/dclock.pro
new file mode 100644
index 000000000..f244d7a51
--- /dev/null
+++ b/examples/dclock/dclock.pro
@@ -0,0 +1,11 @@
+TEMPLATE = app
+TARGET = dclock
+
+CONFIG += qt warn_on release
+DEPENDPATH = ../../include
+
+REQUIRES = large-config
+
+HEADERS = dclock.h
+SOURCES = dclock.cpp \
+ main.cpp
diff --git a/examples/dclock/main.cpp b/examples/dclock/main.cpp
new file mode 100644
index 000000000..eb0dbc837
--- /dev/null
+++ b/examples/dclock/main.cpp
@@ -0,0 +1,23 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for TQt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include "dclock.h"
+#include <qapplication.h>
+
+
+int main( int argc, char **argv )
+{
+ TQApplication a( argc, argv );
+ DigitalClock *clock = new DigitalClock;
+ clock->resize( 170, 80 );
+ a.setMainWidget( clock );
+ clock->setCaption("TQt Example - Digital Clock");
+ clock->show();
+ return a.exec();
+}