author | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
commit | 15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff) | |
tree | c2fa0399a2c47fda8e2cd0092c73a809d17f68eb /core/applets/clockapplet/clock.cpp | |
download | opie-15318cad33835e4e2dc620d033e43cd930676cdd.zip opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2 |
Initial revision
Diffstat (limited to 'core/applets/clockapplet/clock.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/applets/clockapplet/clock.cpp | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/core/applets/clockapplet/clock.cpp b/core/applets/clockapplet/clock.cpp new file mode 100644 index 0000000..178dcbe --- a/dev/null +++ b/core/applets/clockapplet/clock.cpp | |||
@@ -0,0 +1,97 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include "clock.h" | ||
22 | |||
23 | #include <qpe/global.h> | ||
24 | #include <qpe/qpeapplication.h> | ||
25 | #include <qpe/config.h> | ||
26 | |||
27 | #include <qmainwindow.h> | ||
28 | #include <qlayout.h> | ||
29 | #include <qpushbutton.h> | ||
30 | #include <qmessagebox.h> | ||
31 | #include <qdatetime.h> | ||
32 | #include <qtimer.h> | ||
33 | #include <qpopupmenu.h> | ||
34 | #include <stdlib.h> | ||
35 | |||
36 | |||
37 | LauncherClock::LauncherClock( QWidget *parent ) : QLabel( parent ) | ||
38 | { | ||
39 | // If you want a sunken border around the clock do this: | ||
40 | // setFrameStyle( QFrame::Panel | QFrame::Sunken ); | ||
41 | setFont( QFont( "Helvetica", 10, QFont::Normal ) ); | ||
42 | connect( qApp, SIGNAL( timeChanged() ), this, SLOT( updateTime( ) ) ); | ||
43 | connect( qApp, SIGNAL( clockChanged( bool ) ), | ||
44 | this, SLOT( slotClockChanged( bool ) ) ); | ||
45 | Config config( "qpe" ); | ||
46 | config.setGroup( "Time" ); | ||
47 | ampmFormat = config.readBoolEntry( "AMPM", TRUE ); | ||
48 | timerId = 0; | ||
49 | timerEvent( 0 ); | ||
50 | show(); | ||
51 | } | ||
52 | |||
53 | void LauncherClock::mouseReleaseEvent( QMouseEvent * ) | ||
54 | { | ||
55 | Global::execute( "systemtime" ); | ||
56 | } | ||
57 | |||
58 | |||
59 | void LauncherClock::timerEvent( QTimerEvent *e ) | ||
60 | { | ||
61 | if ( !e || e->timerId() == timerId ) { | ||
62 | killTimer( timerId ); | ||
63 | changeTime(); | ||
64 | QTime t = QTime::currentTime(); | ||
65 | int ms = (60 - t.second())*1000 - t.msec(); | ||
66 | timerId = startTimer( ms ); | ||
67 | } else { | ||
68 | QLabel::timerEvent( e ); | ||
69 | } | ||
70 | } | ||
71 | |||
72 | void LauncherClock::updateTime( void ) | ||
73 | { | ||
74 | changeTime(); | ||
75 | } | ||
76 | |||
77 | void LauncherClock::changeTime( void ) | ||
78 | { | ||
79 | QTime tm = QDateTime::currentDateTime().time(); | ||
80 | QString s; | ||
81 | if( ampmFormat ) { | ||
82 | int hour = tm.hour(); | ||
83 | if (hour == 0) | ||
84 | hour = 12; | ||
85 | if (hour > 12) | ||
86 | hour -= 12; | ||
87 | s.sprintf( "%2d%c%02d %s", hour, ':', tm.minute(), (tm.hour() >= 12) ? "PM" : "AM" ); | ||
88 | } else | ||
89 | s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() ); | ||
90 | setText( s ); | ||
91 | } | ||
92 | |||
93 | void LauncherClock::slotClockChanged( bool pm ) | ||
94 | { | ||
95 | ampmFormat = pm; | ||
96 | updateTime(); | ||
97 | } | ||