author | llornkcor <llornkcor> | 2003-03-04 16:50:17 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2003-03-04 16:50:17 (UTC) |
commit | bb765b9cd286d85eb8fa1d18199dfb7a29d57fc5 (patch) (unidiff) | |
tree | 80d69eef2975d1fb27a758aea7629d34c678a270 | |
parent | 628a783e5d7ec07b5c073c94a77b614439d937ba (diff) | |
download | opie-bb765b9cd286d85eb8fa1d18199dfb7a29d57fc5.zip opie-bb765b9cd286d85eb8fa1d18199dfb7a29d57fc5.tar.gz opie-bb765b9cd286d85eb8fa1d18199dfb7a29d57fc5.tar.bz2 |
added 3 qcop calls. timerStart(), timerStop() and timerReset()
-rw-r--r-- | noncore/tools/clock/clock.cpp | 429 | ||||
-rw-r--r-- | noncore/tools/clock/clock.h | 15 |
2 files changed, 250 insertions, 194 deletions
diff --git a/noncore/tools/clock/clock.cpp b/noncore/tools/clock/clock.cpp index 0937362..9898332 100644 --- a/noncore/tools/clock/clock.cpp +++ b/noncore/tools/clock/clock.cpp | |||
@@ -1,586 +1,635 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 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 | 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 | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 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. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | // changes added and Copyright (C) by L. J. Potter <ljp@llornkcor.com> 2002 | 20 | // changes added and Copyright (C) by L. J. Potter <ljp@llornkcor.com> 2002 |
21 | 21 | ||
22 | #include "clock.h" | 22 | #include "clock.h" |
23 | #include "setAlarm.h" | 23 | #include "setAlarm.h" |
24 | 24 | ||
25 | #include <qpe/qpeapplication.h> | 25 | #include <qpe/qpeapplication.h> |
26 | #include <qpe/qcopenvelope_qws.h> | 26 | #include <qpe/qcopenvelope_qws.h> |
27 | #include <qpe/config.h> | 27 | #include <qpe/config.h> |
28 | #include <qpe/timestring.h> | 28 | #include <qpe/timestring.h> |
29 | #include <qpe/alarmserver.h> | 29 | #include <qpe/alarmserver.h> |
30 | #include <qpe/sound.h> | 30 | #include <qpe/sound.h> |
31 | #include <qpe/resource.h> | 31 | #include <qpe/resource.h> |
32 | #include <qsound.h> | 32 | #include <qsound.h> |
33 | #include <qtimer.h> | 33 | #include <qtimer.h> |
34 | 34 | ||
35 | #include <opie/oclickablelabel.h> | 35 | #include <opie/oclickablelabel.h> |
36 | 36 | ||
37 | #include <qlcdnumber.h> | 37 | #include <qlcdnumber.h> |
38 | #include <qslider.h> | 38 | #include <qslider.h> |
39 | #include <qlabel.h> | 39 | #include <qlabel.h> |
40 | #include <qlayout.h> | 40 | #include <qlayout.h> |
41 | #include <qtimer.h> | 41 | #include <qtimer.h> |
42 | #include <qpushbutton.h> | 42 | #include <qpushbutton.h> |
43 | #include <qradiobutton.h> | 43 | #include <qradiobutton.h> |
44 | #include <qbuttongroup.h> | 44 | #include <qbuttongroup.h> |
45 | #include <qpainter.h> | 45 | #include <qpainter.h> |
46 | #include <qmessagebox.h> | 46 | #include <qmessagebox.h> |
47 | #include <qdatetime.h> | 47 | #include <qdatetime.h> |
48 | 48 | ||
49 | #include <math.h> | 49 | #include <math.h> |
50 | #include <unistd.h> | 50 | #include <unistd.h> |
51 | #include <sys/types.h> | 51 | #include <sys/types.h> |
52 | 52 | ||
53 | #include <pthread.h> | 53 | #include <pthread.h> |
54 | 54 | ||
55 | 55 | ||
56 | const double deg2rad = 0.017453292519943295769; // pi/180 | 56 | const double deg2rad = 0.017453292519943295769; // pi/180 |
57 | const int sw_prec = 2; | 57 | const int sw_prec = 2; |
58 | 58 | ||
59 | void startPlayer() | 59 | void startPlayer() |
60 | { | 60 | { |
61 | Config config( "qpe" ); | 61 | Config config( "qpe" ); |
62 | config.setGroup( "Time" ); | 62 | config.setGroup( "Time" ); |
63 | sleep(15); | 63 | sleep(15); |
64 | QCopEnvelope e( "QPE/Application/opieplayer", "setDocument(QString)" ); | 64 | QCopEnvelope e( "QPE/Application/opieplayer", "setDocument(QString)" ); |
65 | e << config.readEntry( "mp3File", "" ); | 65 | e << config.readEntry( "mp3File", "" ); |
66 | } | 66 | } |
67 | 67 | ||
68 | 68 | ||
69 | static void toggleScreenSaver( bool on ) | 69 | static void toggleScreenSaver( bool on ) |
70 | { | 70 | { |
71 | QCopEnvelope e( "QPE/System", "setScreenSaverMode(int)" ); | 71 | QCopEnvelope e( "QPE/System", "setScreenSaverMode(int)" ); |
72 | e << ( on ? QPEApplication::Enable : QPEApplication::DisableSuspend ); | 72 | e << ( on ? QPEApplication::Enable : QPEApplication::DisableSuspend ); |
73 | } | 73 | } |
74 | 74 | ||
75 | Clock::Clock( QWidget * parent, const char * name, WFlags f ) | 75 | Clock::Clock( QWidget * parent, const char * name, WFlags f ) |
76 | : QVBox( parent, name , f ) | 76 | : QVBox( parent, name , f ) |
77 | { | 77 | { |
78 | setSpacing( 4 ); | 78 | setSpacing( 4 ); |
79 | setMargin( 1 ); | 79 | setMargin( 1 ); |
80 | 80 | ||
81 | Config config( "qpe" ); | ||
82 | config.setGroup( "Time" ); | ||
83 | ampm = config.readBoolEntry( "AMPM", TRUE ); | ||
84 | |||
85 | 81 | ||
86 | snoozeBtn = new QPushButton ( this ); | 82 | snoozeBtn = new QPushButton ( this ); |
87 | snoozeBtn->setText( tr( "Snooze" ) ); | 83 | snoozeBtn->setText( tr( "Snooze" ) ); |
88 | 84 | ||
89 | aclock = new AnalogClock( this ); | 85 | aclock = new AnalogClock( this ); |
90 | aclock->display( QTime::currentTime() ); | 86 | aclock->display( QTime::currentTime() ); |
91 | aclock->setLineWidth( 2 ); | 87 | aclock->setLineWidth( 2 ); |
92 | 88 | ||
93 | QHBox *hb = new QHBox( this ); | 89 | QHBox *hb = new QHBox( this ); |
94 | hb->setMargin( 0 ); | 90 | hb->setMargin( 0 ); |
95 | QWidget *space = new QWidget( hb ); | 91 | QWidget *space = new QWidget( hb ); |
96 | lcd = new QLCDNumber( hb ); | 92 | lcd = new QLCDNumber( hb ); |
97 | lcd->setSegmentStyle( QLCDNumber::Flat ); | 93 | lcd->setSegmentStyle( QLCDNumber::Flat ); |
98 | lcd->setFrameStyle( QFrame::NoFrame ); | 94 | lcd->setFrameStyle( QFrame::NoFrame ); |
99 | lcd->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) ); | 95 | lcd->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) ); |
100 | lcd->setFixedHeight( 23 ); | 96 | lcd->setFixedHeight( 23 ); |
101 | 97 | ||
102 | ampmLabel = new QLabel( tr( "PM" ), hb ); | 98 | ampmLabel = new QLabel( tr( "PM" ), hb ); |
103 | ampmLabel->setFont( QFont( "Helvetica", 14, QFont::Bold ) ); | 99 | ampmLabel->setFont( QFont( "Helvetica", 14, QFont::Bold ) ); |
104 | ampmLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred ) ); | 100 | ampmLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred ) ); |
105 | ampmLabel->setAlignment( AlignLeft | AlignBottom ); | 101 | ampmLabel->setAlignment( AlignLeft | AlignBottom ); |
106 | space = new QWidget( hb ); | 102 | space = new QWidget( hb ); |
107 | 103 | ||
108 | date = new QLabel( this ); | 104 | date = new QLabel( this ); |
109 | date->setAlignment( AlignHCenter | AlignVCenter ); | 105 | date->setAlignment( AlignHCenter | AlignVCenter ); |
110 | date->setFont( QFont( "Helvetica", 14, QFont::Bold ) ); | 106 | date->setFont( QFont( "Helvetica", 14, QFont::Bold ) ); |
111 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); | 107 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); |
112 | 108 | ||
113 | QWidget *controls = new QWidget( this ); | 109 | QWidget *controls = new QWidget( this ); |
114 | QGridLayout *gl = new QGridLayout( controls, 3, 2, 6, 4 ); | 110 | QGridLayout *gl = new QGridLayout( controls, 3, 2, 6, 4 ); |
115 | 111 | ||
116 | QButtonGroup *grp = new QButtonGroup( controls ); | 112 | QButtonGroup *grp = new QButtonGroup( controls ); |
117 | grp->setRadioButtonExclusive( true ); | 113 | grp->setRadioButtonExclusive( true ); |
118 | grp->hide(); | 114 | grp->hide(); |
119 | 115 | ||
120 | clockRB = new QRadioButton ( tr( "Clock" ), controls ); | 116 | clockRB = new QRadioButton ( tr( "Clock" ), controls ); |
121 | gl->addWidget( clockRB, 0, 0 ); | 117 | gl->addWidget( clockRB, 0, 0 ); |
122 | grp->insert( clockRB ); | 118 | grp->insert( clockRB ); |
123 | 119 | ||
124 | swatchRB = new QRadioButton ( tr( "Stopwatch" ), controls ); | 120 | swatchRB = new QRadioButton ( tr( "Stopwatch" ), controls ); |
125 | gl->addWidget( swatchRB, 1, 0 ); | 121 | gl->addWidget( swatchRB, 1, 0 ); |
126 | grp->insert( swatchRB ); | 122 | grp->insert( swatchRB ); |
127 | 123 | ||
128 | connect( grp, SIGNAL( clicked( int ) ), this, SLOT( modeSelect( int ) ) ); | 124 | connect( grp, SIGNAL( clicked( int ) ), this, SLOT( modeSelect( int ) ) ); |
129 | grp->setButton( 0 ); | 125 | grp->setButton( 0 ); |
130 | 126 | ||
131 | set | 127 | set = new QPushButton ( controls ); |
132 | = new QPushButton ( controls ); | 128 | set->setMaximumSize( 50, 30 ); |
133 | set | 129 | gl->addWidget( set , 0, 1 ); |
134 | ->setMaximumSize( 50, 30 ); | 130 | set->setText( tr( "Start" ) ); |
135 | gl->addWidget( set | 131 | set->setEnabled( FALSE ); |
136 | , 0, 1 ); | 132 | grp->insert( set ); |
137 | set | ||
138 | ->setText( tr( "Start" ) ); | ||
139 | set | ||
140 | ->setEnabled( FALSE ); | ||
141 | grp->insert( set | ||
142 | ); | ||
143 | 133 | ||
144 | reset = new QPushButton ( controls ); | 134 | reset = new QPushButton ( controls ); |
145 | gl->addWidget( reset, 1, 1 ); | 135 | gl->addWidget( reset, 1, 1 ); |
146 | reset->setText( tr( "Reset" ) ); | 136 | reset->setText( tr( "Reset" ) ); |
147 | reset->setEnabled( FALSE ); | 137 | reset->setEnabled( FALSE ); |
148 | grp->insert( reset ); | 138 | grp->insert( reset ); |
149 | 139 | ||
150 | alarmOffBtn = new QPushButton ( controls ); | 140 | alarmOffBtn = new QPushButton ( controls ); |
151 | // alarmOffBtn->setMaximumSize(60,30); | ||
152 | gl->addWidget( alarmOffBtn, 0, 2 ); | 141 | gl->addWidget( alarmOffBtn, 0, 2 ); |
153 | 142 | ||
154 | alarmBtn = new QPushButton ( controls ); | 143 | alarmBtn = new QPushButton ( controls ); |
155 | // alarmBtn->setMaximumSize(60,30); | ||
156 | gl->addWidget( alarmBtn, 1, 2 ); | 144 | gl->addWidget( alarmBtn, 1, 2 ); |
145 | |||
157 | alarmBtn->setText( tr( "Set Alarm" ) ); | 146 | alarmBtn->setText( tr( "Set Alarm" ) ); |
158 | 147 | ||
159 | OClickableLabel *click = new OClickableLabel( controls, "label" ); | 148 | OClickableLabel *click = new OClickableLabel( controls, "label" ); |
160 | click->setText( tr( "Set date and time." ) ); | 149 | click->setText( tr( "Set date and time." ) ); |
161 | gl->addMultiCellWidget( click, 3, 3, 0, 2, AlignHCenter ); | 150 | gl->addMultiCellWidget( click, 3, 3, 0, 2, AlignHCenter ); |
162 | connect( click, SIGNAL( clicked() ), this, SLOT( slotAdjustTime() ) ); | 151 | connect( click, SIGNAL( clicked() ), this, SLOT( slotAdjustTime() ) ); |
163 | 152 | ||
164 | connect( set | 153 | connect( set , SIGNAL( pressed() ), SLOT( slotSet() ) ); |
165 | , SIGNAL( pressed() ), SLOT( slotSet() ) ); | ||
166 | connect( reset, SIGNAL( clicked() ), SLOT( slotReset() ) ); | 154 | connect( reset, SIGNAL( clicked() ), SLOT( slotReset() ) ); |
167 | 155 | ||
168 | connect( alarmBtn, SIGNAL( clicked() ), SLOT( slotSetAlarm() ) ); | 156 | connect( alarmBtn, SIGNAL( clicked() ), SLOT( slotSetAlarm() ) ); |
169 | connect( snoozeBtn, SIGNAL( clicked() ), SLOT( slotSnooze() ) ); | 157 | connect( snoozeBtn, SIGNAL( clicked() ), SLOT( slotSnooze() ) ); |
170 | connect( alarmOffBtn, SIGNAL( clicked() ), SLOT( slotToggleAlarm() ) ); | 158 | connect( alarmOffBtn, SIGNAL( clicked() ), SLOT( slotToggleAlarm() ) ); |
171 | 159 | ||
172 | connect( qApp, SIGNAL( appMessage( const QCString&, const QByteArray& ) ), | 160 | connect( qApp, SIGNAL( appMessage( const QCString&, const QByteArray& ) ), |
173 | this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); | 161 | this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); |
174 | 162 | ||
175 | t = new QTimer( this ); | 163 | t = new QTimer( this ); |
176 | connect( t, SIGNAL( timeout() ), SLOT( updateClock() ) ); | 164 | connect( t, SIGNAL( timeout() ), SLOT( updateClock() ) ); |
177 | t->start( 1000 ); | 165 | t->start( 1000 ); |
178 | 166 | ||
179 | connect( qApp, SIGNAL( timeChanged() ), SLOT( updateClock() ) ); | 167 | connect( qApp, SIGNAL( timeChanged() ), SLOT( updateClock() ) ); |
180 | 168 | ||
181 | swatch_running = FALSE; | 169 | swatch_running = FALSE; |
182 | swatch_totalms = 0; | 170 | swatch_totalms = 0; |
183 | 171 | ||
184 | connect( qApp, SIGNAL( clockChanged( bool ) ), this, SLOT( changeClock( bool ) ) ); | 172 | connect( qApp, SIGNAL( clockChanged( bool ) ), this, SLOT( changeClock( bool ) ) ); |
185 | 173 | ||
174 | |||
175 | Config config( "qpe" ); | ||
176 | config.setGroup( "Time" ); | ||
177 | ampm = config.readBoolEntry( "AMPM", TRUE ); | ||
178 | |||
186 | QString tmp = config.readEntry( "clockAlarmHour", "" ); | 179 | QString tmp = config.readEntry( "clockAlarmHour", "" ); |
187 | bool ok; | 180 | bool ok; |
188 | hour = tmp.toInt( &ok, 10 ); | 181 | hour = tmp.toInt( &ok, 10 ); |
189 | tmp = config.readEntry( "clockAlarmMinute", "" ); | 182 | tmp = config.readEntry( "clockAlarmMinute", "" ); |
190 | minute = tmp.toInt( &ok, 10 ); | 183 | minute = tmp.toInt( &ok, 10 ); |
191 | 184 | ||
192 | if ( config.readEntry( "clockAlarmSet", "FALSE" ) == "TRUE" ) { | 185 | if ( config.readEntry( "clockAlarmSet", "FALSE" ) == "TRUE" ) |
193 | alarmOffBtn->setText( tr( "Alarm Is On" ) ); | 186 | { |
194 | alarmBool = TRUE; | 187 | alarmOffBtn->setText( tr( "Alarm Is On" ) ); |
195 | snoozeBtn->show(); | 188 | alarmBool = TRUE; |
196 | } | 189 | snoozeBtn->show(); |
197 | else { | 190 | } |
198 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); | 191 | else |
199 | alarmBool = FALSE; | 192 | { |
200 | snoozeBtn->hide(); | 193 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); |
201 | } | 194 | alarmBool = FALSE; |
195 | snoozeBtn->hide(); | ||
196 | } | ||
202 | 197 | ||
203 | QTimer::singleShot( 0, this, SLOT( updateClock() ) ); | 198 | QTimer::singleShot( 0, this, SLOT( updateClock() ) ); |
204 | modeSelect( 0 ); | 199 | |
200 | Config cfg( "Clock" ); | ||
201 | cfg.setGroup( "Mode" ); | ||
202 | int mode = cfg.readBoolEntry( "clockMode");setSwatchMode( mode); | ||
203 | modeSelect( mode); | ||
205 | } | 204 | } |
206 | 205 | ||
207 | Clock::~Clock() | 206 | Clock::~Clock() |
208 | { | 207 | { |
209 | toggleScreenSaver( true ); | 208 | toggleScreenSaver( true ); |
210 | } | 209 | } |
211 | 210 | ||
212 | void Clock::updateClock() | 211 | void Clock::updateClock() |
213 | { | 212 | { |
214 | if ( clockRB->isChecked() ) { | 213 | if ( clockRB->isChecked() ) |
215 | QTime tm = QDateTime::currentDateTime().time(); | 214 | { |
216 | QString s; | 215 | QTime tm = QDateTime::currentDateTime().time(); |
217 | if ( ampm ) { | 216 | QString s; |
218 | int hour = tm.hour(); | 217 | if ( ampm ) |
219 | if ( hour == 0 ) | 218 | { |
220 | hour = 12; | 219 | int hour = tm.hour(); |
221 | if ( hour > 12 ) | 220 | if ( hour == 0 ) |
222 | hour -= 12; | 221 | hour = 12; |
223 | s.sprintf( "%2d%c%02d", hour, ':', tm.minute() ); | 222 | if ( hour > 12 ) |
224 | ampmLabel->setText( ( tm.hour() >= 12 ) ? "PM" : "AM" ); | 223 | hour -= 12; |
225 | ampmLabel->show(); | 224 | s.sprintf( "%2d%c%02d", hour, ':', tm.minute() ); |
226 | } | 225 | ampmLabel->setText( ( tm.hour() >= 12 ) ? "PM" : "AM" ); |
227 | else { | 226 | ampmLabel->show(); |
228 | s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() ); | 227 | } |
229 | ampmLabel->hide(); | 228 | else |
230 | } | 229 | { |
231 | lcd->display( s ); | 230 | s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() ); |
232 | lcd->repaint( FALSE ); | 231 | ampmLabel->hide(); |
233 | aclock->display( QTime::currentTime() ); | 232 | } |
234 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); | 233 | lcd->display( s ); |
235 | } | 234 | lcd->repaint( FALSE ); |
236 | else { | 235 | aclock->display( QTime::currentTime() ); |
237 | QTime swatch_time; | 236 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); |
238 | QString lcdtext; | 237 | } |
239 | int totalms = swatch_totalms; | 238 | else |
240 | if ( swatch_running ) | 239 | { |
241 | totalms += swatch_start.elapsed(); | 240 | QTime swatch_time; |
242 | swatch_time = QTime( 0, 0, 0 ).addMSecs( totalms ); | 241 | QString lcdtext; |
243 | QString d = swatch_running ? QString( " " ) | 242 | int totalms = swatch_totalms; |
244 | : QString::number( totalms % 1000 + 1000 ); | 243 | if ( swatch_running ) |
245 | lcdtext = swatch_time.toString() + "." + d.right( 3 ).left( sw_prec ); | 244 | totalms += swatch_start.elapsed(); |
246 | lcd->display( lcdtext ); | 245 | swatch_time = QTime( 0, 0, 0 ).addMSecs( totalms ); |
247 | lcd->repaint( FALSE ); | 246 | QString d = swatch_running ? QString( " " ) |
248 | aclock->display( swatch_time ); | 247 | : QString::number( totalms % 1000 + 1000 ); |
249 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); | 248 | lcdtext = swatch_time.toString() + "." + d.right( 3 ).left( sw_prec ); |
250 | } | 249 | lcd->display( lcdtext ); |
250 | lcd->repaint( FALSE ); | ||
251 | aclock->display( swatch_time ); | ||
252 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); | ||
253 | } | ||
251 | } | 254 | } |
252 | 255 | ||
253 | void Clock::changeClock( bool a ) | 256 | void Clock::changeClock( bool a ) |
254 | { | 257 | { |
255 | ampm = a; | 258 | ampm = a; |
256 | updateClock(); | 259 | updateClock(); |
257 | } | 260 | } |
258 | 261 | ||
259 | void Clock::clearClock( void ) | 262 | void Clock::clearClock( void ) |
260 | { | 263 | { |
261 | lcd->display( QTime( 0, 0, 0 ).toString() ); | 264 | lcd->display( QTime( 0, 0, 0 ).toString() ); |
262 | aclock->display( QTime( 0, 0, 0 ) ); | 265 | aclock->display( QTime( 0, 0, 0 ) ); |
263 | } | 266 | } |
264 | 267 | ||
265 | void Clock::slotSet() | 268 | void Clock::slotSet() |
266 | { | 269 | { |
267 | if ( t->isActive() ) { | 270 | if ( t->isActive() ) |
268 | swatch_totalms += swatch_start.elapsed(); | 271 | { |
269 | set | 272 | swatch_totalms += swatch_start.elapsed(); |
270 | ->setText( tr( "Start" ) ); | 273 | set->setText( tr( "Start" ) ); |
271 | t->stop(); | 274 | t->stop(); |
272 | swatch_running = FALSE; | 275 | swatch_running = FALSE; |
273 | toggleScreenSaver( TRUE ); | 276 | toggleScreenSaver( TRUE ); |
274 | updateClock(); | 277 | updateClock(); |
275 | } | 278 | } |
276 | else { | 279 | else |
277 | swatch_start.start(); | 280 | { |
278 | set | 281 | swatch_start.start(); |
279 | ->setText( tr( "Stop" ) ); | 282 | set->setText( tr( "Stop" ) ); |
280 | t->start( 1000 ); | 283 | t->start( 1000 ); |
281 | swatch_running = TRUE; | 284 | swatch_running = TRUE; |
282 | // disable screensaver while stop watch is running | 285 | // disable screensaver while stop watch is running |
283 | toggleScreenSaver( FALSE ); | 286 | toggleScreenSaver( FALSE ); |
284 | } | 287 | } |
285 | } | 288 | } |
286 | 289 | ||
287 | void Clock::slotReset() | 290 | void Clock::slotReset() |
288 | { | 291 | { |
289 | t->stop(); | 292 | t->stop(); |
290 | swatch_start.start(); | 293 | swatch_start.start(); |
291 | swatch_totalms = 0; | 294 | swatch_totalms = 0; |
292 | 295 | ||
293 | if ( swatch_running ) | 296 | if ( swatch_running ) |
294 | t->start( 1000 ); | 297 | t->start( 1000 ); |
295 | 298 | ||
296 | updateClock(); | 299 | updateClock(); |
297 | } | 300 | } |
298 | 301 | ||
299 | void Clock::modeSelect( int m ) | 302 | void Clock::modeSelect( int m ) |
300 | { | 303 | { |
301 | if ( m ) { | 304 | qDebug("Clock::modeSelect( %d) ", m); |
302 | lcd->setNumDigits( 8 + 1 + sw_prec ); | 305 | if ( m ) |
303 | lcd->setMinimumWidth( lcd->sizeHint().width() ); | 306 | { |
304 | set | 307 | lcd->setNumDigits( 8 + 1 + sw_prec ); |
305 | ->setEnabled( TRUE ); | 308 | lcd->setMinimumWidth( lcd->sizeHint().width() ); |
306 | reset->setEnabled( TRUE ); | 309 | set->setEnabled( TRUE ); |
307 | ampmLabel->hide(); | 310 | reset->setEnabled( TRUE ); |
308 | 311 | ampmLabel->hide(); | |
309 | if ( !swatch_running ) | 312 | |
310 | t->stop(); | 313 | if ( !swatch_running ) |
311 | } | 314 | t->stop(); |
312 | else { | 315 | } |
313 | lcd->setNumDigits( 5 ); | 316 | else |
314 | lcd->setMinimumWidth( lcd->sizeHint().width() ); | 317 | { |
315 | set | 318 | lcd->setNumDigits( 5 ); |
316 | ->setEnabled( FALSE ); | 319 | lcd->setMinimumWidth( lcd->sizeHint().width() ); |
317 | reset->setEnabled( FALSE ); | 320 | set->setEnabled( FALSE ); |
318 | t->start( 1000 ); | 321 | reset->setEnabled( FALSE ); |
319 | } | 322 | t->start( 1000 ); |
323 | } | ||
324 | |||
325 | Config config( "Clock" ); | ||
326 | config.setGroup( "Mode" ); | ||
327 | config.writeEntry( "clockMode", m ); | ||
320 | updateClock(); | 328 | updateClock(); |
321 | } | 329 | } |
322 | 330 | ||
323 | //this sets the alarm time | 331 | //this sets the alarm time |
324 | void Clock::slotSetAlarm() | 332 | void Clock::slotSetAlarm() |
325 | { | 333 | { |
326 | if ( !snoozeBtn->isHidden() ) | 334 | if ( !snoozeBtn->isHidden() ) |
327 | slotToggleAlarm(); | 335 | slotToggleAlarm(); |
328 | Set_Alarm *setAlarmDlg; | 336 | Set_Alarm *setAlarmDlg; |
329 | setAlarmDlg = new Set_Alarm( this, "SetAlarm", TRUE ); | 337 | setAlarmDlg = new Set_Alarm( this, "SetAlarm", TRUE ); |
330 | int result = setAlarmDlg->exec(); | 338 | int result = setAlarmDlg->exec(); |
331 | if ( result == 1 ) { | 339 | if ( result == 1 ) { |
332 | Config config( "qpe" ); | 340 | Config config( "qpe" ); |
333 | config.setGroup( "Time" ); | 341 | config.setGroup( "Time" ); |
334 | QString tmp; | 342 | QString tmp; |
335 | hour = setAlarmDlg->Hour_Slider->value(); | 343 | hour = setAlarmDlg->Hour_Slider->value(); |
336 | minute = setAlarmDlg->Minute_Slider->value(); | 344 | minute = setAlarmDlg->Minute_Slider->value(); |
337 | snoozeTime = setAlarmDlg->SnoozeSlider->value(); | 345 | snoozeTime = setAlarmDlg->SnoozeSlider->value(); |
338 | if ( ampm ) { | 346 | if ( ampm ) { |
339 | if ( hour == 12 ) | 347 | if ( hour == 12 ) |
340 | hour = 0; | 348 | hour = 0; |
341 | 349 | ||
342 | if ( setAlarmDlg->Pm_RadioButton->isChecked() && hour < 12 ) | 350 | if ( setAlarmDlg->Pm_RadioButton->isChecked() && hour < 12 ) |
343 | hour += 12; | 351 | hour += 12; |
344 | } | 352 | } |
345 | config.writeEntry( "clockAlarmHour", tmp.setNum( hour ), 10 ); | 353 | config.writeEntry( "clockAlarmHour", tmp.setNum( hour ), 10 ); |
346 | config.writeEntry( "clockAlarmMinute", tmp.setNum( minute ), 10 ); | 354 | config.writeEntry( "clockAlarmMinute", tmp.setNum( minute ), 10 ); |
347 | config.writeEntry( "clockAlarmSnooze", tmp.setNum( snoozeTime ), 10 ); | 355 | config.writeEntry( "clockAlarmSnooze", tmp.setNum( snoozeTime ), 10 ); |
348 | config.write(); | 356 | config.write(); |
349 | } | 357 | } |
350 | } | 358 | } |
351 | 359 | ||
352 | void Clock::slotSnooze() | 360 | void Clock::slotSnooze() |
353 | { | 361 | { |
354 | bSound = FALSE; | 362 | bSound = FALSE; |
355 | int warn = 0; | 363 | int warn = 0; |
356 | QTime t = QTime::currentTime(); | 364 | QTime t = QTime::currentTime(); |
357 | QDateTime whenl( when.date(), t.addSecs( snoozeTime * 60 ) ); | 365 | QDateTime whenl( when.date(), t.addSecs( snoozeTime * 60 ) ); |
358 | when = whenl; | 366 | when = whenl; |
359 | AlarmServer::addAlarm( when, | 367 | AlarmServer::addAlarm( when, |
360 | "QPE/Application/clock", | 368 | "QPE/Application/clock", |
361 | "alarm(QDateTime,int)", warn ); | 369 | "alarm(QDateTime,int)", warn ); |
362 | 370 | ||
363 | } | 371 | } |
364 | 372 | ||
365 | //toggles alarm on/off | 373 | //toggles alarm on/off |
366 | void Clock::slotToggleAlarm() | 374 | void Clock::slotToggleAlarm() |
367 | { | 375 | { |
368 | Config config( "qpe" ); | 376 | Config config( "qpe" ); |
369 | config.setGroup( "Time" ); | 377 | config.setGroup( "Time" ); |
370 | if ( alarmBool ) { | 378 | if ( alarmBool ) |
371 | config.writeEntry( "clockAlarmSet", "FALSE" ); | 379 | { |
372 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); | 380 | config.writeEntry( "clockAlarmSet", "FALSE" ); |
373 | snoozeBtn->hide(); | 381 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); |
374 | alarmBool = FALSE; | 382 | snoozeBtn->hide(); |
375 | alarmOff(); | 383 | alarmBool = FALSE; |
376 | } | 384 | alarmOff(); |
377 | else { | 385 | } |
378 | config.writeEntry( "clockAlarmSet", "TRUE" ); | 386 | else |
379 | alarmOffBtn->setText( tr( "Alarm Is On" ) ); | 387 | { |
380 | snoozeBtn->show(); | 388 | config.writeEntry( "clockAlarmSet", "TRUE" ); |
381 | alarmBool = TRUE; | 389 | alarmOffBtn->setText( tr( "Alarm Is On" ) ); |
382 | alarmOn(); | 390 | snoozeBtn->show(); |
383 | } | 391 | alarmBool = TRUE; |
392 | alarmOn(); | ||
393 | } | ||
384 | config.write(); | 394 | config.write(); |
385 | } | 395 | } |
386 | 396 | ||
387 | void Clock::alarmOn() | 397 | void Clock::alarmOn() |
388 | { | 398 | { |
389 | QDate d = QDate::currentDate(); | 399 | QDate d = QDate::currentDate(); |
390 | QTime tm( ( int ) hour, ( int ) minute, 0 ); | 400 | QTime tm( ( int ) hour, ( int ) minute, 0 ); |
391 | qDebug( "Time set " + tm.toString() ); | 401 | qDebug( "Time set " + tm.toString() ); |
392 | QTime t = QTime::currentTime(); | 402 | QTime t = QTime::currentTime(); |
393 | if ( t > tm ) | 403 | if ( t > tm ) |
394 | d = d.addDays( 1 ); | 404 | d = d.addDays( 1 ); |
395 | int warn = 0; | 405 | int warn = 0; |
396 | QDateTime whenl( d, tm ); | 406 | QDateTime whenl( d, tm ); |
397 | when = whenl; | 407 | when = whenl; |
398 | AlarmServer::addAlarm( when, | 408 | AlarmServer::addAlarm( when, |
399 | "QPE/Application/clock", | 409 | "QPE/Application/clock", |
400 | "alarm(QDateTime,int)", warn ); | 410 | "alarm(QDateTime,int)", warn ); |
401 | setCaption( "Alarm set: " + whenl.toString() ); | 411 | setCaption( "Alarm set: " + whenl.toString() ); |
402 | } | 412 | } |
403 | 413 | ||
404 | void Clock::alarmOff() | 414 | void Clock::alarmOff() |
405 | { | 415 | { |
406 | int warn = 0; | 416 | int warn = 0; |
407 | bSound = FALSE; | 417 | bSound = FALSE; |
408 | AlarmServer::deleteAlarm( when, | 418 | AlarmServer::deleteAlarm( when, |
409 | "QPE/Application/clock", | 419 | "QPE/Application/clock", |
410 | "alarm(QDateTime,int)", warn ); | 420 | "alarm(QDateTime,int)", warn ); |
411 | qDebug( "Alarm Off " + when.toString() ); | 421 | qDebug( "Alarm Off " + when.toString() ); |
412 | setCaption( "Clock" ); | 422 | setCaption( "Clock" ); |
413 | } | 423 | } |
414 | 424 | ||
415 | void Clock::clearTimer() | 425 | void Clock::clearTimer() |
416 | { | 426 | { |
417 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); | 427 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); |
418 | alarmBool = FALSE; | 428 | alarmBool = FALSE; |
419 | snoozeBtn->hide(); | 429 | snoozeBtn->hide(); |
420 | setCaption( "Clock" ); | 430 | setCaption( "Clock" ); |
421 | } | 431 | } |
422 | 432 | ||
423 | void Clock::appMessage( const QCString& msg, const QByteArray& /*data*/ ) | 433 | void Clock::appMessage( const QCString& msg, const QByteArray& /*data*/ ) |
424 | { | 434 | { |
425 | int stopTimer = 0; | 435 | int stopTimer = 0; |
426 | int timerStay = 5000; | 436 | int timerStay = 5000; |
427 | bSound = TRUE; | 437 | bSound = TRUE; |
428 | qDebug( "Message received in clock" ); | 438 | qDebug( "Message received in clock" ); |
429 | if ( msg == "alarm(QDateTime,int)" ) { | 439 | if ( msg == "alarm(QDateTime,int)" ) |
430 | Config config( "qpe" ); | 440 | { |
431 | config.setGroup( "Time" ); | 441 | Config config( "qpe" ); |
432 | if ( config.readBoolEntry( "mp3Alarm", 0 ) ) | 442 | config.setGroup( "Time" ); |
433 | { | 443 | if ( config.readBoolEntry( "mp3Alarm", 0 ) ) |
434 | clearTimer(); | 444 | { |
435 | // pid_t pid; | 445 | clearTimer(); |
436 | // switch(pid = fork()) | 446 | pthread_t thread; |
437 | // { | 447 | pthread_create(&thread, NULL, (void * (*) (void *))startPlayer, NULL/* &*/); |
438 | // case -1: | 448 | |
439 | // {//failed | 449 | } |
440 | // } | 450 | else |
441 | // break; | 451 | { |
442 | // case 0: | 452 | |
443 | // {//child | 453 | Sound::soundAlarm(); |
444 | // QCopEnvelope e( "QPE/Application/opieplayer", "setDocument(QString)" ); | 454 | stopTimer = startTimer( timerStay ); |
445 | // e << config.readEntry( "mp3File", "" ); | 455 | } |
446 | pthread_t thread; | 456 | } |
447 | pthread_create(&thread, NULL, (void * (*) (void *))startPlayer, NULL/* &*/); | 457 | |
448 | // startPlayer(); | 458 | if ( msg == "timerStart()" ) |
449 | // } | 459 | { |
450 | // break; | 460 | slotStartTimer(); |
451 | // }; | 461 | } |
452 | 462 | if ( msg == "timerStop()" ) | |
453 | } | 463 | { |
454 | else | 464 | slotStopTimer(); |
455 | { | 465 | } |
466 | if ( msg == "timerReset()" ) | ||
467 | { | ||
468 | slotResetTimer(); | ||
469 | } | ||
456 | 470 | ||
457 | Sound::soundAlarm(); | ||
458 | stopTimer = startTimer( timerStay ); | ||
459 | } | ||
460 | } | ||
461 | show(); | 471 | show(); |
462 | raise(); | 472 | raise(); |
463 | QPEApplication::setKeepRunning(); | 473 | QPEApplication::setKeepRunning(); |
464 | setActiveWindow(); | 474 | setActiveWindow(); |
465 | } | 475 | } |
466 | 476 | ||
467 | void Clock::timerEvent( QTimerEvent *e ) | 477 | void Clock::timerEvent( QTimerEvent *e ) |
468 | { | 478 | { |
469 | static int stop = 0; | 479 | static int stop = 0; |
470 | if ( stop < 120 && bSound ) { | 480 | if ( stop < 120 && bSound ) |
471 | Sound::soundAlarm(); | 481 | { |
472 | stop++; | 482 | Sound::soundAlarm(); |
473 | } | 483 | stop++; |
474 | else { | 484 | } |
475 | stop = 0; | 485 | else |
476 | killTimer( e->timerId() ); | 486 | { |
477 | clearTimer(); | 487 | stop = 0; |
478 | setCaption( tr( "Clock: Alarm was missed." ) ); | 488 | killTimer( e->timerId() ); |
479 | } | 489 | clearTimer(); |
490 | setCaption( tr( "Clock: Alarm was missed." ) ); | ||
491 | } | ||
480 | } | 492 | } |
481 | 493 | ||
482 | 494 | ||
483 | QSizePolicy AnalogClock::sizePolicy() const | 495 | QSizePolicy AnalogClock::sizePolicy() const |
484 | { | 496 | { |
485 | return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); | 497 | return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); |
486 | } | 498 | } |
487 | 499 | ||
488 | void AnalogClock::drawContents( QPainter *p ) | 500 | void AnalogClock::drawContents( QPainter *p ) |
489 | { | 501 | { |
490 | QRect r = contentsRect(); | 502 | QRect r = contentsRect(); |
491 | QRect fr; | 503 | QRect fr; |
492 | 504 | ||
493 | if ( r. width ( ) > r. height ( )) | 505 | if ( r. width ( ) > r. height ( )) |
494 | fr. setRect (( r. width ( ) - r. height ( )) / 2, r. y ( ), r. height ( ), r. height ( )); | 506 | fr. setRect (( r. width ( ) - r. height ( )) / 2, r. y ( ), r. height ( ), r. height ( )); |
495 | else | 507 | else |
496 | fr. setRect ( r. x ( ), ( r. height ( ) - r. width ( )) / 2, r. width ( ), r. width ( )); | 508 | fr. setRect ( r. x ( ), ( r. height ( ) - r. width ( )) / 2, r. width ( ), r. width ( )); |
497 | 509 | ||
498 | QPoint center = fr. center ( ); // ( fr.x() + fr.width() / 2, fr.y() + fr.height() / 2 ); | 510 | QPoint center = fr. center ( ); // ( fr.x() + fr.width() / 2, fr.y() + fr.height() / 2 ); |
499 | QPoint l1 ( center. x ( ), fr. y ( ) + 2 ); | 511 | QPoint l1 ( center. x ( ), fr. y ( ) + 2 ); |
500 | QPoint l2 ( center. x ( ), fr. y ( ) + 8 ); | 512 | QPoint l2 ( center. x ( ), fr. y ( ) + 8 ); |
501 | 513 | ||
502 | 514 | ||
503 | 515 | ||
504 | if ( clear ) { | 516 | if ( clear ) |
505 | erase ( r ); | 517 | { |
506 | p-> setPen ( NoPen ); | 518 | erase ( r ); |
507 | p-> setBrush ( colorGroup ( ). color ( QColorGroup::Base )); | 519 | p-> setPen ( NoPen ); |
508 | p-> drawEllipse ( fr ); | 520 | p-> setBrush ( colorGroup ( ). color ( QColorGroup::Base )); |
509 | p-> setBrush ( NoBrush ); | 521 | p-> drawEllipse ( fr ); |
522 | p-> setBrush ( NoBrush ); | ||
523 | |||
524 | // draw ticks | ||
525 | p->setPen( QPen( colorGroup ( ). color ( QColorGroup::Text ), 1 ) ); | ||
526 | for ( int i = 0; i < 12; i++ ) | ||
527 | p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) ); | ||
528 | } | ||
529 | else | ||
530 | { | ||
531 | drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Base ), prevTime, &currTime ); | ||
532 | } | ||
510 | 533 | ||
511 | // draw ticks | ||
512 | p->setPen( QPen( colorGroup ( ). color ( QColorGroup::Text ), 1 ) ); | ||
513 | for ( int i = 0; i < 12; i++ ) | ||
514 | p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) ); | ||
515 | } | ||
516 | else { | ||
517 | drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Base ), prevTime, &currTime ); | ||
518 | } | ||
519 | |||
520 | drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Text ), currTime ); | 534 | drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Text ), currTime ); |
521 | 535 | ||
522 | prevTime = currTime; | 536 | prevTime = currTime; |
523 | } | 537 | } |
524 | 538 | ||
525 | void AnalogClock::drawPointers ( QPainter *p, const QRect &r, const QColor &c, const QTime &t, const QTime *t2 ) | 539 | void AnalogClock::drawPointers ( QPainter *p, const QRect &r, const QColor &c, const QTime &t, const QTime *t2 ) |
526 | { | 540 | { |
527 | QPoint center = r. center ( ); | 541 | QPoint center = r. center ( ); |
528 | 542 | ||
529 | QPoint h1( center. x ( ), r. y ( ) + r. height ( ) / 4 ); | 543 | QPoint h1( center. x ( ), r. y ( ) + r. height ( ) / 4 ); |
530 | QPoint h2( center. x ( ), center. y ( ) ); | 544 | QPoint h2( center. x ( ), center. y ( ) ); |
531 | 545 | ||
532 | QPoint m1( center. x ( ), r.y() + r.height() / 8 ); | 546 | QPoint m1( center. x ( ), r.y() + r.height() / 8 ); |
533 | QPoint m2( center. x ( ), center. y ( ) ); | 547 | QPoint m2( center. x ( ), center. y ( ) ); |
534 | 548 | ||
535 | QPoint s1( center. x ( ), r. y ( ) + 8 ); | 549 | QPoint s1( center. x ( ), r. y ( ) + 8 ); |
536 | QPoint s2( center. x ( ), center. y ( ) ); | 550 | QPoint s2( center. x ( ), center. y ( ) ); |
537 | 551 | ||
538 | 552 | ||
539 | if ( !t2 || ( t. minute ( ) != t2-> minute ( ) || t. hour ( ) != t2-> hour ( ))) { | 553 | if ( !t2 || ( t. minute ( ) != t2-> minute ( ) || t. hour ( ) != t2-> hour ( ))) { |
540 | // draw hour pointer | 554 | // draw hour pointer |
541 | h1 = rotate( center, h1, 30 * ( t.hour() % 12 ) + t.minute() / 2 ); | 555 | h1 = rotate( center, h1, 30 * ( t.hour() % 12 ) + t.minute() / 2 ); |
542 | h2 = rotate( center, h2, 30 * ( t.hour() % 12 ) + t.minute() / 2 ); | 556 | h2 = rotate( center, h2, 30 * ( t.hour() % 12 ) + t.minute() / 2 ); |
543 | p-> setPen ( QPen ( c, 3 )); | 557 | p-> setPen ( QPen ( c, 3 )); |
544 | p-> drawLine ( h1, h2 ); | 558 | p-> drawLine ( h1, h2 ); |
545 | } | 559 | } |
546 | 560 | ||
547 | if ( !t2 || ( t. minute ( ) != t2-> minute ( ))) { | 561 | if ( !t2 || ( t. minute ( ) != t2-> minute ( ))) { |
548 | // draw minute pointer | 562 | // draw minute pointer |
549 | m1 = rotate( center, m1, t.minute() * 6 ); | 563 | m1 = rotate( center, m1, t.minute() * 6 ); |
550 | m2 = rotate( center, m2, t.minute() * 6 ); | 564 | m2 = rotate( center, m2, t.minute() * 6 ); |
551 | p-> setPen ( QPen ( c, 2 )); | 565 | p-> setPen ( QPen ( c, 2 )); |
552 | p-> drawLine ( m1, m2 ); | 566 | p-> drawLine ( m1, m2 ); |
553 | } | 567 | } |
554 | 568 | ||
555 | if ( !t2 || ( t. second ( ) != t2-> second ( ))) { | 569 | if ( !t2 || ( t. second ( ) != t2-> second ( ))) { |
556 | // draw second pointer | 570 | // draw second pointer |
557 | s1 = rotate( center, s1, t.second() * 6 ); | 571 | s1 = rotate( center, s1, t.second() * 6 ); |
558 | s2 = rotate( center, s2, t.second() * 6 ); | 572 | s2 = rotate( center, s2, t.second() * 6 ); |
559 | p-> setPen ( QPen ( c, 1 )); | 573 | p-> setPen ( QPen ( c, 1 )); |
560 | p-> drawLine ( s1, s2 ); | 574 | p-> drawLine ( s1, s2 ); |
561 | } | 575 | } |
562 | } | 576 | } |
563 | 577 | ||
564 | void AnalogClock::display( const QTime& t ) | 578 | void AnalogClock::display( const QTime& t ) |
565 | { | 579 | { |
566 | currTime = t; | 580 | currTime = t; |
567 | clear = false; | 581 | clear = false; |
568 | repaint( false ); | 582 | repaint( false ); |
569 | clear = true; | 583 | clear = true; |
570 | } | 584 | } |
571 | 585 | ||
572 | QPoint AnalogClock::rotate( QPoint c, QPoint p, int a ) | 586 | QPoint AnalogClock::rotate( QPoint c, QPoint p, int a ) |
573 | { | 587 | { |
574 | double angle = deg2rad * ( - a + 180 ); | 588 | double angle = deg2rad * ( - a + 180 ); |
575 | double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) - | 589 | double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) - |
576 | ( p.y() - c.y() ) * sin( angle ); | 590 | ( p.y() - c.y() ) * sin( angle ); |
577 | double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) + | 591 | double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) + |
578 | ( p.x() - c.x() ) * sin( angle ); | 592 | ( p.x() - c.x() ) * sin( angle ); |
579 | return QPoint( nx, ny ); | 593 | return QPoint( nx, ny ); |
580 | } | 594 | } |
581 | 595 | ||
582 | void Clock::slotAdjustTime() | 596 | void Clock::slotAdjustTime() |
583 | { | 597 | { |
584 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 598 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
585 | e << QString( "systemtime" ); | 599 | e << QString( "systemtime" ); |
586 | } | 600 | } |
601 | |||
602 | void Clock::slotStartTimer() | ||
603 | { | ||
604 | Config cfg( "Clock" ); | ||
605 | cfg.setGroup( "Mode" ); | ||
606 | int mode = cfg.readBoolEntry( "clockMode"); | ||
607 | if ( clockRB->isChecked() ) | ||
608 | setSwatchMode( 1); | ||
609 | slotSet(); | ||
610 | } | ||
611 | |||
612 | void Clock::slotStopTimer() | ||
613 | { | ||
614 | Config cfg( "Clock" ); | ||
615 | cfg.setGroup( "Mode" ); | ||
616 | int mode = cfg.readBoolEntry( "clockMode"); | ||
617 | if ( clockRB->isChecked() ) | ||
618 | setSwatchMode( 1); | ||
619 | slotSet(); | ||
620 | } | ||
621 | |||
622 | void Clock::slotResetTimer() | ||
623 | { | ||
624 | if ( clockRB->isChecked() ) | ||
625 | setSwatchMode( 1); | ||
626 | slotReset(); | ||
627 | } | ||
628 | |||
629 | void Clock::setSwatchMode(int mode) | ||
630 | { | ||
631 | qDebug("Clock::setSwatchMode( %d)"), mode; | ||
632 | swatchRB->setChecked( mode); | ||
633 | clearClock( ); | ||
634 | modeSelect( mode ); | ||
635 | } | ||
diff --git a/noncore/tools/clock/clock.h b/noncore/tools/clock/clock.h index 23cc143..9b00e28 100644 --- a/noncore/tools/clock/clock.h +++ b/noncore/tools/clock/clock.h | |||
@@ -1,99 +1,106 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 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 | 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 | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 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. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #ifndef CLOCK_H | 20 | #ifndef CLOCK_H |
21 | #define CLOCK_H | 21 | #define CLOCK_H |
22 | 22 | ||
23 | #include <qdatetime.h> | 23 | #include <qdatetime.h> |
24 | #include <qvbox.h> | 24 | #include <qvbox.h> |
25 | 25 | ||
26 | class QLCDNumber; | 26 | class QLCDNumber; |
27 | class QLabel; | 27 | class QLabel; |
28 | class QTimer; | 28 | class QTimer; |
29 | class QRadioButton; | 29 | class QRadioButton; |
30 | class QPushButton; | 30 | class QPushButton; |
31 | class QDateTime; | 31 | class QDateTime; |
32 | 32 | ||
33 | class AnalogClock : public QFrame | 33 | class AnalogClock : public QFrame |
34 | { | 34 | { |
35 | Q_OBJECT | 35 | Q_OBJECT |
36 | 36 | ||
37 | public: | 37 | public: |
38 | AnalogClock( QWidget * parent = 0, const char * name = 0 ) | 38 | AnalogClock( QWidget * parent = 0, const char * name = 0 ) |
39 | : QFrame( parent, name ), clear(true) {} | 39 | : QFrame( parent, name ), clear(true) {} |
40 | 40 | ||
41 | QSizePolicy sizePolicy() const; | 41 | QSizePolicy sizePolicy() const; |
42 | 42 | ||
43 | void display( const QTime& time ); | 43 | void display( const QTime& time ); |
44 | 44 | ||
45 | protected: | 45 | protected: |
46 | void drawContents( QPainter *p ); | 46 | void drawContents( QPainter *p ); |
47 | 47 | ||
48 | private: | 48 | private: |
49 | QPoint rotate( QPoint center, QPoint p, int angle ); | ||
50 | void drawPointers ( QPainter *, const QRect &r, const QColor &c, const QTime &t, const QTime *t2 = 0 ); | ||
51 | 49 | ||
52 | QTime currTime; | 50 | QTime currTime; |
53 | QTime prevTime; | 51 | QTime prevTime; |
54 | bool clear; | 52 | bool clear; |
53 | |||
54 | QPoint rotate( QPoint center, QPoint p, int angle ); | ||
55 | void drawPointers ( QPainter *, const QRect &r, const QColor &c, const QTime &t, const QTime *t2 = 0 ); | ||
56 | |||
55 | }; | 57 | }; |
56 | 58 | ||
57 | class Clock : public QVBox | 59 | class Clock : public QVBox |
58 | { | 60 | { |
59 | Q_OBJECT | 61 | Q_OBJECT |
60 | 62 | ||
61 | public: | 63 | public: |
62 | Clock( QWidget * parent = 0, const char * name = 0, WFlags f=0 ); | 64 | Clock( QWidget * parent = 0, const char * name = 0, WFlags f=0 ); |
63 | ~Clock(); | 65 | ~Clock(); |
64 | QDateTime when; | 66 | QDateTime when; |
65 | bool bSound; | 67 | bool bSound; |
66 | int hour, minute, snoozeTime; | 68 | int hour, minute, snoozeTime; |
67 | private slots: | 69 | private slots: |
68 | void slotSet(); | 70 | void slotSet(); |
69 | void slotReset(); | 71 | void slotReset(); |
70 | void modeSelect(int); | 72 | void modeSelect(int); |
71 | void updateClock(); | 73 | void updateClock(); |
72 | void changeClock( bool ); | 74 | void changeClock( bool ); |
73 | void slotSetAlarm(); | 75 | void slotSetAlarm(); |
74 | void slotSnooze(); | 76 | void slotSnooze(); |
75 | void slotToggleAlarm(); | 77 | void slotToggleAlarm(); |
76 | void alarmOn(); | 78 | void alarmOn(); |
77 | void alarmOff(); | 79 | void alarmOff(); |
78 | void appMessage(const QCString& msg, const QByteArray& data); | 80 | void appMessage(const QCString& msg, const QByteArray& data); |
79 | void timerEvent( QTimerEvent *e ); | 81 | void timerEvent( QTimerEvent *e ); |
80 | void slotAdjustTime(); | 82 | void slotAdjustTime(); |
83 | |||
84 | void slotStartTimer(); | ||
85 | void slotStopTimer(); | ||
86 | void slotResetTimer(); | ||
87 | void setSwatchMode( int ); | ||
81 | private: | 88 | private: |
82 | void clearClock(); | ||
83 | void clearTimer(); | ||
84 | bool alarmBool; | 89 | bool alarmBool; |
85 | QTimer *t; | 90 | QTimer *t; |
86 | QLCDNumber *lcd; | 91 | QLCDNumber *lcd; |
87 | QLabel *date; | 92 | QLabel *date; |
88 | QLabel *ampmLabel; | 93 | QLabel *ampmLabel; |
89 | QPushButton *set, *reset, *alarmBtn, *snoozeBtn, *alarmOffBtn; | 94 | QPushButton *set, *reset, *alarmBtn, *snoozeBtn, *alarmOffBtn; |
90 | QRadioButton *clockRB, *swatchRB; | 95 | QRadioButton *clockRB, *swatchRB; |
91 | AnalogClock *aclock; | 96 | AnalogClock *aclock; |
92 | QTime swatch_start; | 97 | QTime swatch_start; |
93 | int swatch_totalms; | 98 | int swatch_totalms; |
94 | bool swatch_running; | 99 | bool swatch_running; |
95 | bool ampm; | 100 | bool ampm; |
101 | void clearClock(); | ||
102 | void clearTimer(); | ||
96 | }; | 103 | }; |
97 | 104 | ||
98 | #endif | 105 | #endif |
99 | 106 | ||