summaryrefslogtreecommitdiffstats
path: root/kmahjongg/GameTimer.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitc90c389a8a8d9d8661e9772ec4144c5cf2039f23 (patch)
tree6d8391395bce9eaea4ad78958617edb20c6a7573 /kmahjongg/GameTimer.cpp
downloadtdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.tar.gz
tdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegames@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kmahjongg/GameTimer.cpp')
-rw-r--r--kmahjongg/GameTimer.cpp94
1 files changed, 94 insertions, 0 deletions
diff --git a/kmahjongg/GameTimer.cpp b/kmahjongg/GameTimer.cpp
new file mode 100644
index 00000000..5eb827d9
--- /dev/null
+++ b/kmahjongg/GameTimer.cpp
@@ -0,0 +1,94 @@
+/*
+ * Based upon the QT example dclock
+ */
+
+#include <stdio.h>
+#include "GameTimer.h"
+#include "GameTimer.moc"
+
+
+//
+// Constructs a GameTimer widget with a parent and a name.
+//
+
+GameTimer::GameTimer( QWidget *parent, const char *name )
+ : QLCDNumber( parent, name )
+{
+ showingColon = false;
+ setNumDigits(7);
+ setFrameStyle(QFrame::Panel | QFrame::Sunken);
+ setFrameStyle(QFrame::NoFrame);
+ timerMode = stopped;
+ showTime(); // display the current time1
+ startTimer( 500 ); // 1/2 second timer events
+}
+
+// QObject timer call back implementation
+void GameTimer::timerEvent( QTimerEvent * )
+{
+ if (timerMode == running)
+ theTimer=theTimer.addMSecs(500);
+ showTime();
+}
+
+
+//
+// Shows the current time in the internal lcd widget.
+//
+
+void GameTimer::showTime()
+{
+ QString s;
+ showingColon = !showingColon; // toggle/blink colon
+
+ switch(timerMode) {
+ case paused:
+ case running:
+ s = theTimer.toString();
+ break;
+ case stopped:
+ s = "00:00:00";
+ break;
+ }
+
+ if ( !showingColon )
+ s[2] = s[5] = ' ';
+ display( s ); // set LCD number/text
+}
+
+void GameTimer::start() {
+ theTimer.setHMS(0,0,0);
+ timerMode = running;
+}
+
+
+void GameTimer::fromString(const char*tim) {
+ int h,m,s;
+ sscanf(tim, "%2d:%2d:%2d\n", &h, &m, &s);
+ theTimer.setHMS(h,m,s);
+ timerMode = running;
+}
+
+
+void GameTimer::stop() {
+ timerMode = stopped;
+}
+
+void GameTimer::pause() {
+
+ if (timerMode == stopped)
+ return;
+
+ if (timerMode == paused) {
+ timerMode = running;
+ } else {
+ timerMode = paused;
+ }
+}
+
+int GameTimer::toInt() {
+
+ return (theTimer.second()+
+ theTimer.minute()*60+
+ theTimer.hour()*360);
+}