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 /noncore/tools/clock | |
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 | |||
@@ -16,7 +16,7 @@ | |||
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" |
@@ -58,11 +58,11 @@ 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 | ||
@@ -78,10 +78,6 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f ) | |||
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" ) ); |
@@ -128,18 +124,12 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f ) | |||
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 ); |
@@ -148,12 +138,11 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f ) | |||
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" ); |
@@ -161,8 +150,7 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f ) | |||
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() ) ); |
@@ -183,25 +171,36 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f ) | |||
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() |
@@ -211,43 +210,47 @@ Clock::~Clock() | |||
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 ) |
@@ -264,24 +267,24 @@ void Clock::clearClock( void ) | |||
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() |
@@ -298,25 +301,30 @@ void Clock::slotReset() | |||
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 | ||
@@ -367,20 +375,22 @@ 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 | ||
@@ -414,10 +424,10 @@ void Clock::alarmOff() | |||
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*/ ) |
@@ -426,38 +436,38 @@ void Clock::appMessage( const QCString& msg, const QByteArray& /*data*/ ) | |||
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(); |
@@ -467,16 +477,18 @@ void Clock::appMessage( const QCString& msg, const QByteArray& /*data*/ ) | |||
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 | ||
@@ -494,31 +506,33 @@ void AnalogClock::drawContents( QPainter *p ) | |||
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 | ||
@@ -537,7 +551,7 @@ void AnalogClock::drawPointers ( QPainter *p, const QRect &r, const QColor &c, c | |||
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 )); |
@@ -545,7 +559,7 @@ void AnalogClock::drawPointers ( QPainter *p, const QRect &r, const QColor &c, c | |||
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 )); |
@@ -553,7 +567,7 @@ void AnalogClock::drawPointers ( QPainter *p, const QRect &r, const QColor &c, c | |||
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 )); |
@@ -584,3 +598,38 @@ void Clock::slotAdjustTime() | |||
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 | |||
@@ -46,12 +46,14 @@ 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 |
@@ -78,9 +80,12 @@ private slots: | |||
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; |
@@ -93,6 +98,8 @@ private: | |||
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 |