Diffstat (limited to 'noncore/tools/clock/clock.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/tools/clock/clock.cpp | 380 |
1 files changed, 197 insertions, 183 deletions
diff --git a/noncore/tools/clock/clock.cpp b/noncore/tools/clock/clock.cpp index 0eb2b83..74b7147 100644 --- a/noncore/tools/clock/clock.cpp +++ b/noncore/tools/clock/clock.cpp | |||
@@ -49,29 +49,29 @@ | |||
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 | { |
@@ -174,177 +174,191 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f ) | |||
174 | 174 | ||
175 | Config config( "qpe" ); | 175 | Config config( "qpe" ); |
176 | config.setGroup( "Time" ); | 176 | config.setGroup( "Time" ); |
177 | ampm = config.readBoolEntry( "AMPM", TRUE ); | 177 | ampm = config.readBoolEntry( "AMPM", TRUE ); |
178 | 178 | ||
179 | QString tmp = config.readEntry( "clockAlarmHour", "" ); | 179 | QString tmp = config.readEntry( "clockAlarmHour", "" ); |
180 | bool ok; | 180 | bool ok; |
181 | hour = tmp.toInt( &ok, 10 ); | 181 | hour = tmp.toInt( &ok, 10 ); |
182 | tmp = config.readEntry( "clockAlarmMinute", "" ); | 182 | tmp = config.readEntry( "clockAlarmMinute", "" ); |
183 | minute = tmp.toInt( &ok, 10 ); | 183 | minute = tmp.toInt( &ok, 10 ); |
184 | 184 | ||
185 | if ( config.readEntry( "clockAlarmSet", "FALSE" ) == "TRUE" ) | 185 | if ( config.readEntry( "clockAlarmSet", "FALSE" ) == "TRUE" ) |
186 | { | 186 | { |
187 | alarmOffBtn->setText( tr( "Alarm Is On" ) ); | 187 | alarmOffBtn->setText( tr( "Alarm Is On" ) ); |
188 | alarmBool = TRUE; | 188 | alarmBool = TRUE; |
189 | snoozeBtn->show(); | 189 | snoozeBtn->show(); |
190 | } | 190 | } |
191 | else | 191 | else |
192 | { | 192 | { |
193 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); | 193 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); |
194 | alarmBool = FALSE; | 194 | alarmBool = FALSE; |
195 | snoozeBtn->hide(); | 195 | snoozeBtn->hide(); |
196 | } | 196 | } |
197 | 197 | ||
198 | QTimer::singleShot( 0, this, SLOT( updateClock() ) ); | 198 | QTimer::singleShot( 0, this, SLOT( updateClock() ) ); |
199 | 199 | ||
200 | Config cfg( "Clock" ); | 200 | Config cfg( "Clock" ); |
201 | cfg.setGroup( "Mode" ); | 201 | cfg.setGroup( "Mode" ); |
202 | int mode = cfg.readBoolEntry( "clockMode");setSwatchMode( mode); | 202 | int mode = cfg.readBoolEntry( "clockMode"); |
203 | modeSelect( mode); | 203 | setSwatchMode( mode); |
204 | modeSelect( mode); | ||
204 | } | 205 | } |
205 | 206 | ||
206 | Clock::~Clock() | 207 | Clock::~Clock() |
207 | { | 208 | { |
208 | toggleScreenSaver( true ); | 209 | toggleScreenSaver( true ); |
209 | } | 210 | } |
210 | 211 | ||
211 | void Clock::updateClock() | 212 | void Clock::updateClock() |
212 | { | 213 | { |
213 | if ( clockRB->isChecked() ) | 214 | if ( clockRB->isChecked() ) |
214 | { | 215 | { |
215 | QTime tm = QDateTime::currentDateTime().time(); | 216 | QTime tm = QDateTime::currentDateTime().time(); |
216 | QString s; | 217 | QString s; |
217 | if ( ampm ) | 218 | if ( ampm ) |
218 | { | 219 | { |
219 | int hour = tm.hour(); | 220 | int hour = tm.hour(); |
220 | if ( hour == 0 ) | 221 | if ( hour == 0 ) |
221 | hour = 12; | 222 | hour = 12; |
222 | if ( hour > 12 ) | 223 | if ( hour > 12 ) |
223 | hour -= 12; | 224 | hour -= 12; |
224 | s.sprintf( "%2d%c%02d", hour, ':', tm.minute() ); | 225 | s.sprintf( "%2d%c%02d", hour, ':', tm.minute() ); |
225 | ampmLabel->setText( ( tm.hour() >= 12 ) ? "PM" : "AM" ); | 226 | ampmLabel->setText( ( tm.hour() >= 12 ) ? "PM" : "AM" ); |
226 | ampmLabel->show(); | 227 | ampmLabel->show(); |
227 | } | 228 | } |
228 | else | 229 | else |
229 | { | 230 | { |
230 | s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() ); | 231 | s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() ); |
231 | ampmLabel->hide(); | 232 | ampmLabel->hide(); |
232 | } | 233 | } |
233 | lcd->display( s ); | 234 | lcd->display( s ); |
234 | lcd->repaint( FALSE ); | 235 | lcd->repaint( FALSE ); |
235 | aclock->display( QTime::currentTime() ); | 236 | aclock->display( QTime::currentTime() ); |
236 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); | 237 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); |
237 | } | 238 | } |
238 | else | 239 | else |
239 | { | 240 | { |
240 | QTime swatch_time; | 241 | QTime swatch_time; |
241 | QString lcdtext; | 242 | QString lcdtext; |
242 | int totalms = swatch_totalms; | 243 | int totalms = swatch_totalms; |
243 | if ( swatch_running ) | 244 | if ( swatch_running ) |
244 | totalms += swatch_start.elapsed(); | 245 | totalms += swatch_start.elapsed(); |
245 | swatch_time = QTime( 0, 0, 0 ).addMSecs( totalms ); | 246 | swatch_time = QTime( 0, 0, 0 ).addMSecs( totalms ); |
246 | QString d = swatch_running ? QString( " " ) | 247 | QString d = swatch_running ? QString( " " ) |
247 | : QString::number( totalms % 1000 + 1000 ); | 248 | : QString::number( totalms % 1000 + 1000 ); |
248 | lcdtext = swatch_time.toString() + "." + d.right( 3 ).left( sw_prec ); | 249 | lcdtext = swatch_time.toString() + "." + d.right( 3 ).left( sw_prec ); |
249 | lcd->display( lcdtext ); | 250 | lcd->display( lcdtext ); |
250 | lcd->repaint( FALSE ); | 251 | lcd->repaint( FALSE ); |
251 | aclock->display( swatch_time ); | 252 | aclock->display( swatch_time ); |
252 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); | 253 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); |
253 | } | 254 | } |
254 | } | 255 | } |
255 | 256 | ||
256 | void Clock::changeClock( bool a ) | 257 | void Clock::changeClock( bool a ) |
257 | { | 258 | { |
258 | ampm = a; | 259 | ampm = a; |
259 | updateClock(); | 260 | updateClock(); |
260 | } | 261 | } |
261 | 262 | ||
262 | void Clock::clearClock( void ) | 263 | void Clock::clearClock( void ) |
263 | { | 264 | { |
264 | lcd->display( QTime( 0, 0, 0 ).toString() ); | 265 | lcd->display( QTime( 0, 0, 0 ).toString() ); |
265 | aclock->display( QTime( 0, 0, 0 ) ); | 266 | aclock->display( QTime( 0, 0, 0 ) ); |
266 | } | 267 | } |
267 | 268 | ||
268 | void Clock::startSWatch() | 269 | void Clock::startSWatch() |
269 | { | 270 | { |
270 | swatch_start.start(); | 271 | if(swatch_running) { |
271 | set->setText( tr( "Stop" ) ); | 272 | stopSWatch(); |
272 | t->start( 1000 ); | 273 | return; |
273 | swatch_running = TRUE; | 274 | } |
274 | // disable screensaver while stop watch is running | 275 | qDebug("startSWatch()"); |
275 | toggleScreenSaver( FALSE ); | 276 | swatch_start.start(); |
277 | set->setText( tr( "Stop" ) ); | ||
278 | t->start( 1000 ); | ||
279 | swatch_running = TRUE; | ||
280 | // disable screensaver while stop watch is running | ||
281 | toggleScreenSaver( FALSE ); | ||
276 | } | 282 | } |
277 | 283 | ||
278 | void Clock::stopSWatch() | 284 | void Clock::stopSWatch() |
279 | { | 285 | { |
280 | swatch_totalms += swatch_start.elapsed(); | 286 | qDebug("stopSWatch()"); |
281 | set->setText( tr( "Start" ) ); | 287 | swatch_totalms += swatch_start.elapsed(); |
282 | t->stop(); | 288 | set->setText( tr( "Start" ) ); |
283 | swatch_running = FALSE; | 289 | t->stop(); |
284 | toggleScreenSaver( TRUE ); | 290 | swatch_running = FALSE; |
285 | updateClock(); | 291 | toggleScreenSaver( TRUE ); |
292 | updateClock(); | ||
286 | } | 293 | } |
287 | 294 | ||
288 | 295 | ||
289 | void Clock::slotSet() | 296 | void Clock::slotSet() |
290 | { | 297 | { |
291 | if ( t->isActive() ) | 298 | if ( t->isActive() ) |
292 | { | 299 | { |
293 | startSWatch(); | 300 | startSWatch(); |
294 | } | 301 | } |
295 | else | 302 | else |
296 | { | 303 | { |
297 | stopSWatch(); | 304 | stopSWatch(); |
298 | } | 305 | } |
299 | } | 306 | } |
300 | 307 | ||
301 | void Clock::slotReset() | 308 | void Clock::slotReset() |
302 | { | 309 | { |
303 | t->stop(); | 310 | t->stop(); |
304 | swatch_start.start(); | 311 | swatch_start.start(); |
305 | swatch_totalms = 0; | 312 | swatch_totalms = 0; |
306 | 313 | ||
307 | if ( swatch_running ) | 314 | if ( swatch_running ) |
308 | t->start( 1000 ); | 315 | t->start( 1000 ); |
309 | 316 | ||
310 | updateClock(); | 317 | updateClock(); |
311 | } | 318 | } |
312 | 319 | ||
313 | void Clock::modeSelect( int m ) | 320 | void Clock::modeSelect( int m ) |
314 | { | 321 | { |
315 | qDebug("Clock::modeSelect( %d) ", m); | 322 | qDebug("Clock::modeSelect( %d) ", m); |
316 | if ( m ) | 323 | if ( m != 0 ) |
317 | { | 324 | { |
318 | lcd->setNumDigits( 8 + 1 + sw_prec ); | 325 | lcd->setNumDigits( 8 + 1 + sw_prec ); |
319 | lcd->setMinimumWidth( lcd->sizeHint().width() ); | 326 | lcd->setMinimumWidth( lcd->sizeHint().width() ); |
320 | set->setEnabled( TRUE ); | 327 | set->setEnabled( TRUE ); |
321 | reset->setEnabled( TRUE ); | 328 | reset->setEnabled( TRUE ); |
322 | ampmLabel->hide(); | 329 | ampmLabel->hide(); |
323 | 330 | ||
324 | if ( !swatch_running ) | 331 | // if(m == 2) { |
325 | t->stop(); | 332 | if ( !swatch_running ) { |
326 | } | 333 | t->start( 1000 ); |
327 | else | 334 | } |
328 | { | 335 | // else |
329 | lcd->setNumDigits( 5 ); | 336 | // { |
330 | lcd->setMinimumWidth( lcd->sizeHint().width() ); | 337 | // stopSWatch(); |
331 | set->setEnabled( FALSE ); | 338 | // } |
332 | reset->setEnabled( FALSE ); | 339 | // } |
333 | t->start( 1000 ); | 340 | } |
334 | } | 341 | else //clock mode |
335 | 342 | { | |
336 | Config config( "Clock" ); | 343 | lcd->setNumDigits( 5 ); |
337 | config.setGroup( "Mode" ); | 344 | lcd->setMinimumWidth( lcd->sizeHint().width() ); |
338 | config.writeEntry( "clockMode", m ); | 345 | set->setEnabled( FALSE ); |
346 | reset->setEnabled( FALSE ); | ||
347 | t->start( 1000 ); | ||
348 | } | ||
349 | |||
350 | Config config( "Clock" ); | ||
351 | config.setGroup( "Mode" ); | ||
352 | config.writeEntry( "clockMode", m ); | ||
339 | updateClock(); | 353 | updateClock(); |
340 | } | 354 | } |
341 | 355 | ||
342 | //this sets the alarm time | 356 | //this sets the alarm time |
343 | void Clock::slotSetAlarm() | 357 | void Clock::slotSetAlarm() |
344 | { | 358 | { |
345 | if ( !snoozeBtn->isHidden() ) | 359 | if ( !snoozeBtn->isHidden() ) |
346 | slotToggleAlarm(); | 360 | slotToggleAlarm(); |
347 | Set_Alarm *setAlarmDlg; | 361 | Set_Alarm *setAlarmDlg; |
348 | setAlarmDlg = new Set_Alarm( this, "SetAlarm", TRUE ); | 362 | setAlarmDlg = new Set_Alarm( this, "SetAlarm", TRUE ); |
349 | int result = setAlarmDlg->exec(); | 363 | int result = setAlarmDlg->exec(); |
350 | if ( result == 1 ) { | 364 | if ( result == 1 ) { |
@@ -378,39 +392,39 @@ void Clock::slotSnooze() | |||
378 | AlarmServer::addAlarm( when, | 392 | AlarmServer::addAlarm( when, |
379 | "QPE/Application/clock", | 393 | "QPE/Application/clock", |
380 | "alarm(QDateTime,int)", warn ); | 394 | "alarm(QDateTime,int)", warn ); |
381 | 395 | ||
382 | } | 396 | } |
383 | 397 | ||
384 | //toggles alarm on/off | 398 | //toggles alarm on/off |
385 | void Clock::slotToggleAlarm() | 399 | void Clock::slotToggleAlarm() |
386 | { | 400 | { |
387 | Config config( "qpe" ); | 401 | Config config( "qpe" ); |
388 | config.setGroup( "Time" ); | 402 | config.setGroup( "Time" ); |
389 | if ( alarmBool ) | 403 | if ( alarmBool ) |
390 | { | 404 | { |
391 | config.writeEntry( "clockAlarmSet", "FALSE" ); | 405 | config.writeEntry( "clockAlarmSet", "FALSE" ); |
392 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); | 406 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); |
393 | snoozeBtn->hide(); | 407 | snoozeBtn->hide(); |
394 | alarmBool = FALSE; | 408 | alarmBool = FALSE; |
395 | alarmOff(); | 409 | alarmOff(); |
396 | } | 410 | } |
397 | else | 411 | else |
398 | { | 412 | { |
399 | config.writeEntry( "clockAlarmSet", "TRUE" ); | 413 | config.writeEntry( "clockAlarmSet", "TRUE" ); |
400 | alarmOffBtn->setText( tr( "Alarm Is On" ) ); | 414 | alarmOffBtn->setText( tr( "Alarm Is On" ) ); |
401 | snoozeBtn->show(); | 415 | snoozeBtn->show(); |
402 | alarmBool = TRUE; | 416 | alarmBool = TRUE; |
403 | alarmOn(); | 417 | alarmOn(); |
404 | } | 418 | } |
405 | config.write(); | 419 | config.write(); |
406 | } | 420 | } |
407 | 421 | ||
408 | void Clock::alarmOn() | 422 | void Clock::alarmOn() |
409 | { | 423 | { |
410 | QDate d = QDate::currentDate(); | 424 | QDate d = QDate::currentDate(); |
411 | QTime tm( ( int ) hour, ( int ) minute, 0 ); | 425 | QTime tm( ( int ) hour, ( int ) minute, 0 ); |
412 | qDebug( "Time set " + tm.toString() ); | 426 | qDebug( "Time set " + tm.toString() ); |
413 | QTime t = QTime::currentTime(); | 427 | QTime t = QTime::currentTime(); |
414 | if ( t > tm ) | 428 | if ( t > tm ) |
415 | d = d.addDays( 1 ); | 429 | d = d.addDays( 1 ); |
416 | int warn = 0; | 430 | int warn = 0; |
@@ -426,89 +440,89 @@ void Clock::alarmOff() | |||
426 | { | 440 | { |
427 | int warn = 0; | 441 | int warn = 0; |
428 | bSound = FALSE; | 442 | bSound = FALSE; |
429 | AlarmServer::deleteAlarm( when, | 443 | AlarmServer::deleteAlarm( when, |
430 | "QPE/Application/clock", | 444 | "QPE/Application/clock", |
431 | "alarm(QDateTime,int)", warn ); | 445 | "alarm(QDateTime,int)", warn ); |
432 | qDebug( "Alarm Off " + when.toString() ); | 446 | qDebug( "Alarm Off " + when.toString() ); |
433 | setCaption( "Clock" ); | 447 | setCaption( "Clock" ); |
434 | } | 448 | } |
435 | 449 | ||
436 | void Clock::clearTimer() | 450 | void Clock::clearTimer() |
437 | { | 451 | { |
438 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); | 452 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); |
439 | alarmBool = FALSE; | 453 | alarmBool = FALSE; |
440 | snoozeBtn->hide(); | 454 | snoozeBtn->hide(); |
441 | setCaption( "Clock" ); | 455 | setCaption( "Clock" ); |
442 | } | 456 | } |
443 | 457 | ||
444 | void Clock::appMessage( const QCString& msg, const QByteArray& /*data*/ ) | 458 | void Clock::appMessage( const QCString& msg, const QByteArray& /*data*/ ) |
445 | { | 459 | { |
446 | int stopTimer = 0; | 460 | int stopTimer = 0; |
447 | int timerStay = 5000; | 461 | int timerStay = 5000; |
448 | bSound = TRUE; | 462 | bSound = TRUE; |
449 | qDebug( "Message received in clock" ); | 463 | qDebug( "Message received in clock" ); |
450 | if ( msg == "alarm(QDateTime,int)" ) | 464 | if ( msg == "alarm(QDateTime,int)" ) |
451 | { | 465 | { |
452 | Config config( "qpe" ); | 466 | Config config( "qpe" ); |
453 | config.setGroup( "Time" ); | 467 | config.setGroup( "Time" ); |
454 | if ( config.readBoolEntry( "mp3Alarm", 0 ) ) | 468 | if ( config.readBoolEntry( "mp3Alarm", 0 ) ) |
455 | { | 469 | { |
456 | clearTimer(); | 470 | clearTimer(); |
457 | pthread_t thread; | 471 | pthread_t thread; |
458 | pthread_create(&thread, NULL, (void * (*) (void *))startPlayer, NULL/* &*/); | 472 | pthread_create(&thread, NULL, (void * (*) (void *))startPlayer, NULL/* &*/); |
459 | 473 | ||
460 | } | 474 | } |
461 | else | 475 | else |
462 | { | 476 | { |
463 | 477 | ||
464 | Sound::soundAlarm(); | 478 | Sound::soundAlarm(); |
465 | stopTimer = startTimer( timerStay ); | 479 | stopTimer = startTimer( timerStay ); |
466 | } | 480 | } |
467 | } | 481 | } |
468 | 482 | ||
469 | if ( msg == "timerStart()" ) | 483 | if ( msg == "timerStart()" ) |
470 | { | 484 | { |
471 | slotStartTimer(); | 485 | slotStartTimer(); |
472 | } | 486 | } |
473 | if ( msg == "timerStop()" ) | 487 | if ( msg == "timerStop()" ) |
474 | { | 488 | { |
475 | slotStopTimer(); | 489 | slotStopTimer(); |
476 | } | 490 | } |
477 | if ( msg == "timerReset()" ) | 491 | if ( msg == "timerReset()" ) |
478 | { | 492 | { |
479 | slotResetTimer(); | 493 | slotResetTimer(); |
480 | } | 494 | } |
481 | 495 | ||
482 | show(); | 496 | show(); |
483 | raise(); | 497 | raise(); |
484 | QPEApplication::setKeepRunning(); | 498 | QPEApplication::setKeepRunning(); |
485 | setActiveWindow(); | 499 | setActiveWindow(); |
486 | } | 500 | } |
487 | 501 | ||
488 | void Clock::timerEvent( QTimerEvent *e ) | 502 | void Clock::timerEvent( QTimerEvent *e ) |
489 | { | 503 | { |
490 | static int stop = 0; | 504 | static int stop = 0; |
491 | if ( stop < 120 && bSound ) | 505 | if ( stop < 120 && bSound ) |
492 | { | 506 | { |
493 | Sound::soundAlarm(); | 507 | Sound::soundAlarm(); |
494 | stop++; | 508 | stop++; |
495 | } | 509 | } |
496 | else | 510 | else |
497 | { | 511 | { |
498 | stop = 0; | 512 | stop = 0; |
499 | killTimer( e->timerId() ); | 513 | killTimer( e->timerId() ); |
500 | clearTimer(); | 514 | clearTimer(); |
501 | setCaption( tr( "Clock: Alarm was missed." ) ); | 515 | setCaption( tr( "Clock: Alarm was missed." ) ); |
502 | } | 516 | } |
503 | } | 517 | } |
504 | 518 | ||
505 | 519 | ||
506 | QSizePolicy AnalogClock::sizePolicy() const | 520 | QSizePolicy AnalogClock::sizePolicy() const |
507 | { | 521 | { |
508 | return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); | 522 | return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); |
509 | } | 523 | } |
510 | 524 | ||
511 | void AnalogClock::drawContents( QPainter *p ) | 525 | void AnalogClock::drawContents( QPainter *p ) |
512 | { | 526 | { |
513 | QRect r = contentsRect(); | 527 | QRect r = contentsRect(); |
514 | QRect fr; | 528 | QRect fr; |
@@ -516,78 +530,78 @@ void AnalogClock::drawContents( QPainter *p ) | |||
516 | if ( r. width ( ) > r. height ( )) | 530 | if ( r. width ( ) > r. height ( )) |
517 | fr. setRect (( r. width ( ) - r. height ( )) / 2, r. y ( ), r. height ( ), r. height ( )); | 531 | fr. setRect (( r. width ( ) - r. height ( )) / 2, r. y ( ), r. height ( ), r. height ( )); |
518 | else | 532 | else |
519 | fr. setRect ( r. x ( ), ( r. height ( ) - r. width ( )) / 2, r. width ( ), r. width ( )); | 533 | fr. setRect ( r. x ( ), ( r. height ( ) - r. width ( )) / 2, r. width ( ), r. width ( )); |
520 | 534 | ||
521 | QPoint center = fr. center ( ); // ( fr.x() + fr.width() / 2, fr.y() + fr.height() / 2 ); | 535 | QPoint center = fr. center ( ); // ( fr.x() + fr.width() / 2, fr.y() + fr.height() / 2 ); |
522 | QPoint l1 ( center. x ( ), fr. y ( ) + 2 ); | 536 | QPoint l1 ( center. x ( ), fr. y ( ) + 2 ); |
523 | QPoint l2 ( center. x ( ), fr. y ( ) + 8 ); | 537 | QPoint l2 ( center. x ( ), fr. y ( ) + 8 ); |
524 | 538 | ||
525 | 539 | ||
526 | 540 | ||
527 | if ( clear ) | 541 | if ( clear ) |
528 | { | 542 | { |
529 | erase ( r ); | 543 | erase ( r ); |
530 | p-> setPen ( NoPen ); | 544 | p-> setPen ( NoPen ); |
531 | p-> setBrush ( colorGroup ( ). color ( QColorGroup::Base )); | 545 | p-> setBrush ( colorGroup ( ). color ( QColorGroup::Base )); |
532 | p-> drawEllipse ( fr ); | 546 | p-> drawEllipse ( fr ); |
533 | p-> setBrush ( NoBrush ); | 547 | p-> setBrush ( NoBrush ); |
534 | 548 | ||
535 | // draw ticks | 549 | // draw ticks |
536 | p->setPen( QPen( colorGroup ( ). color ( QColorGroup::Text ), 1 ) ); | 550 | p->setPen( QPen( colorGroup ( ). color ( QColorGroup::Text ), 1 ) ); |
537 | for ( int i = 0; i < 12; i++ ) | 551 | for ( int i = 0; i < 12; i++ ) |
538 | p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) ); | 552 | p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) ); |
539 | } | 553 | } |
540 | else | 554 | else |
541 | { | 555 | { |
542 | drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Base ), prevTime, &currTime ); | 556 | drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Base ), prevTime, &currTime ); |
543 | } | 557 | } |
544 | 558 | ||
545 | drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Text ), currTime ); | 559 | drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Text ), currTime ); |
546 | 560 | ||
547 | prevTime = currTime; | 561 | prevTime = currTime; |
548 | } | 562 | } |
549 | 563 | ||
550 | void AnalogClock::drawPointers ( QPainter *p, const QRect &r, const QColor &c, const QTime &t, const QTime *t2 ) | 564 | void AnalogClock::drawPointers ( QPainter *p, const QRect &r, const QColor &c, const QTime &t, const QTime *t2 ) |
551 | { | 565 | { |
552 | QPoint center = r. center ( ); | 566 | QPoint center = r. center ( ); |
553 | 567 | ||
554 | QPoint h1( center. x ( ), r. y ( ) + r. height ( ) / 4 ); | 568 | QPoint h1( center. x ( ), r. y ( ) + r. height ( ) / 4 ); |
555 | QPoint h2( center. x ( ), center. y ( ) ); | 569 | QPoint h2( center. x ( ), center. y ( ) ); |
556 | 570 | ||
557 | QPoint m1( center. x ( ), r.y() + r.height() / 8 ); | 571 | QPoint m1( center. x ( ), r.y() + r.height() / 8 ); |
558 | QPoint m2( center. x ( ), center. y ( ) ); | 572 | QPoint m2( center. x ( ), center. y ( ) ); |
559 | 573 | ||
560 | QPoint s1( center. x ( ), r. y ( ) + 8 ); | 574 | QPoint s1( center. x ( ), r. y ( ) + 8 ); |
561 | QPoint s2( center. x ( ), center. y ( ) ); | 575 | QPoint s2( center. x ( ), center. y ( ) ); |
562 | 576 | ||
563 | 577 | ||
564 | if ( !t2 || ( t. minute ( ) != t2-> minute ( ) || t. hour ( ) != t2-> hour ( ))) { | 578 | if ( !t2 || ( t. minute ( ) != t2-> minute ( ) || t. hour ( ) != t2-> hour ( ))) { |
565 | // draw hour pointer | 579 | // draw hour pointer |
566 | h1 = rotate( center, h1, 30 * ( t.hour() % 12 ) + t.minute() / 2 ); | 580 | h1 = rotate( center, h1, 30 * ( t.hour() % 12 ) + t.minute() / 2 ); |
567 | h2 = rotate( center, h2, 30 * ( t.hour() % 12 ) + t.minute() / 2 ); | 581 | h2 = rotate( center, h2, 30 * ( t.hour() % 12 ) + t.minute() / 2 ); |
568 | p-> setPen ( QPen ( c, 3 )); | 582 | p-> setPen ( QPen ( c, 3 )); |
569 | p-> drawLine ( h1, h2 ); | 583 | p-> drawLine ( h1, h2 ); |
570 | } | 584 | } |
571 | 585 | ||
572 | if ( !t2 || ( t. minute ( ) != t2-> minute ( ))) { | 586 | if ( !t2 || ( t. minute ( ) != t2-> minute ( ))) { |
573 | // draw minute pointer | 587 | // draw minute pointer |
574 | m1 = rotate( center, m1, t.minute() * 6 ); | 588 | m1 = rotate( center, m1, t.minute() * 6 ); |
575 | m2 = rotate( center, m2, t.minute() * 6 ); | 589 | m2 = rotate( center, m2, t.minute() * 6 ); |
576 | p-> setPen ( QPen ( c, 2 )); | 590 | p-> setPen ( QPen ( c, 2 )); |
577 | p-> drawLine ( m1, m2 ); | 591 | p-> drawLine ( m1, m2 ); |
578 | } | 592 | } |
579 | 593 | ||
580 | if ( !t2 || ( t. second ( ) != t2-> second ( ))) { | 594 | if ( !t2 || ( t. second ( ) != t2-> second ( ))) { |
581 | // draw second pointer | 595 | // draw second pointer |
582 | s1 = rotate( center, s1, t.second() * 6 ); | 596 | s1 = rotate( center, s1, t.second() * 6 ); |
583 | s2 = rotate( center, s2, t.second() * 6 ); | 597 | s2 = rotate( center, s2, t.second() * 6 ); |
584 | p-> setPen ( QPen ( c, 1 )); | 598 | p-> setPen ( QPen ( c, 1 )); |
585 | p-> drawLine ( s1, s2 ); | 599 | p-> drawLine ( s1, s2 ); |
586 | } | 600 | } |
587 | } | 601 | } |
588 | 602 | ||
589 | void AnalogClock::display( const QTime& t ) | 603 | void AnalogClock::display( const QTime& t ) |
590 | { | 604 | { |
591 | currTime = t; | 605 | currTime = t; |
592 | clear = false; | 606 | clear = false; |
593 | repaint( false ); | 607 | repaint( false ); |
@@ -604,37 +618,37 @@ QPoint AnalogClock::rotate( QPoint c, QPoint p, int a ) | |||
604 | return QPoint( nx, ny ); | 618 | return QPoint( nx, ny ); |
605 | } | 619 | } |
606 | 620 | ||
607 | void Clock::slotAdjustTime() | 621 | void Clock::slotAdjustTime() |
608 | { | 622 | { |
609 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 623 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
610 | e << QString( "systemtime" ); | 624 | e << QString( "systemtime" ); |
611 | } | 625 | } |
612 | 626 | ||
613 | void Clock::slotStartTimer() | 627 | void Clock::slotStartTimer() |
614 | { | 628 | { |
615 | if ( clockRB->isChecked() ) | 629 | if ( clockRB->isChecked() ) |
616 | setSwatchMode( 1); | 630 | setSwatchMode( 1); |
617 | startSWatch(); | 631 | startSWatch(); |
618 | } | 632 | } |
619 | 633 | ||
620 | void Clock::slotStopTimer() | 634 | void Clock::slotStopTimer() |
621 | { | 635 | { |
622 | if ( clockRB->isChecked() ) | 636 | if ( clockRB->isChecked() ) |
623 | setSwatchMode( 1); | 637 | setSwatchMode( 1); |
624 | stopSWatch(); | 638 | stopSWatch(); |
625 | } | 639 | } |
626 | 640 | ||
627 | void Clock::slotResetTimer() | 641 | void Clock::slotResetTimer() |
628 | { | 642 | { |
629 | if ( clockRB->isChecked() ) | 643 | if ( clockRB->isChecked() ) |
630 | setSwatchMode( 1); | 644 | setSwatchMode( 1); |
631 | slotReset(); | 645 | slotReset(); |
632 | } | 646 | } |
633 | 647 | ||
634 | void Clock::setSwatchMode(int mode) | 648 | void Clock::setSwatchMode(int mode) |
635 | { | 649 | { |
636 | qDebug("Clock::setSwatchMode( %d)", mode); | 650 | qDebug("Clock::setSwatchMode( %d)", mode); |
637 | swatchRB->setChecked( mode); | 651 | swatchRB->setChecked( mode); |
638 | clearClock( ); | 652 | clearClock( ); |
639 | modeSelect( mode ); | 653 | modeSelect( mode ); |
640 | } | 654 | } |