summaryrefslogtreecommitdiffstats
path: root/main/dependencies/qt3/examples/dclock
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-07-10 15:24:15 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-07-10 15:24:15 -0500
commit7d523fac5a54f8e695e56f4877fa852608465bc7 (patch)
treef74237f64a396d91997032df9bdf674492529c94 /main/dependencies/qt3/examples/dclock
parent37e3f157c7d76f13de807fa66e36df209e1005fb (diff)
downloadtde-7d523fac5a54f8e695e56f4877fa852608465bc7.tar.gz
tde-7d523fac5a54f8e695e56f4877fa852608465bc7.zip
Add Qt3 development HEAD version
Diffstat (limited to 'main/dependencies/qt3/examples/dclock')
-rw-r--r--main/dependencies/qt3/examples/dclock/README5
-rw-r--r--main/dependencies/qt3/examples/dclock/dclock.cpp97
-rw-r--r--main/dependencies/qt3/examples/dclock/dclock.doc29
-rw-r--r--main/dependencies/qt3/examples/dclock/dclock.h39
-rw-r--r--main/dependencies/qt3/examples/dclock/dclock.pro11
-rw-r--r--main/dependencies/qt3/examples/dclock/main.cpp23
6 files changed, 204 insertions, 0 deletions
diff --git a/main/dependencies/qt3/examples/dclock/README b/main/dependencies/qt3/examples/dclock/README
new file mode 100644
index 000000000..dfa58402f
--- /dev/null
+++ b/main/dependencies/qt3/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/main/dependencies/qt3/examples/dclock/dclock.cpp b/main/dependencies/qt3/examples/dclock/dclock.cpp
new file mode 100644
index 000000000..18d5be0c8
--- /dev/null
+++ b/main/dependencies/qt3/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 Qt. 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( QWidget *parent, const char *name )
+ : QLCDNumber( parent, name )
+{
+ showingColon = FALSE;
+ setFrameStyle( QFrame::Panel | QFrame::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( QTimerEvent *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( QMouseEvent *e )
+{
+ if ( e->button() == QMouseEvent::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;
+ QDate date = QDate::currentDate();
+ QString 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
+ QString s = QTime::currentTime().toString().left(5);
+ if ( !showingColon )
+ s[2] = ' ';
+ if ( s[0] == '0' )
+ s[0] = ' ';
+ display( s ); // set LCD number/text
+}
diff --git a/main/dependencies/qt3/examples/dclock/dclock.doc b/main/dependencies/qt3/examples/dclock/dclock.doc
new file mode 100644
index 000000000..b341b6638
--- /dev/null
+++ b/main/dependencies/qt3/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/main/dependencies/qt3/examples/dclock/dclock.h b/main/dependencies/qt3/examples/dclock/dclock.h
new file mode 100644
index 000000000..562bdd2bb
--- /dev/null
+++ b/main/dependencies/qt3/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 Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#ifndef DCLOCK_H
+#define DCLOCK_H
+
+#include <qlcdnumber.h>
+
+
+class DigitalClock : public QLCDNumber // digital clock widget
+{
+ Q_OBJECT
+public:
+ DigitalClock( QWidget *parent=0, const char *name=0 );
+
+protected: // event handlers
+ void timerEvent( QTimerEvent * );
+ void mousePressEvent( QMouseEvent * );
+
+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/main/dependencies/qt3/examples/dclock/dclock.pro b/main/dependencies/qt3/examples/dclock/dclock.pro
new file mode 100644
index 000000000..f244d7a51
--- /dev/null
+++ b/main/dependencies/qt3/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/main/dependencies/qt3/examples/dclock/main.cpp b/main/dependencies/qt3/examples/dclock/main.cpp
new file mode 100644
index 000000000..fd7b91602
--- /dev/null
+++ b/main/dependencies/qt3/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 Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include "dclock.h"
+#include <qapplication.h>
+
+
+int main( int argc, char **argv )
+{
+ QApplication a( argc, argv );
+ DigitalClock *clock = new DigitalClock;
+ clock->resize( 170, 80 );
+ a.setMainWidget( clock );
+ clock->setCaption("Qt Example - Digital Clock");
+ clock->show();
+ return a.exec();
+}