author | llornkcor <llornkcor> | 2003-03-04 17:22:54 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2003-03-04 17:22:54 (UTC) |
commit | 55e5d2c95f70d296c541e4f2564713a593c3851c (patch) (unidiff) | |
tree | 63e2a6b4c8429baac265826e3695bd3e185afc07 | |
parent | ca913d1f2035b6ddb77be497516e4dfc2371e5b3 (diff) | |
download | opie-55e5d2c95f70d296c541e4f2564713a593c3851c.zip opie-55e5d2c95f70d296c541e4f2564713a593c3851c.tar.gz opie-55e5d2c95f70d296c541e4f2564713a593c3851c.tar.bz2 |
make timerStart called twice just reset, instead of stop
-rw-r--r-- | noncore/tools/clock/clock.cpp | 47 | ||||
-rw-r--r-- | noncore/tools/clock/clock.h | 2 |
2 files changed, 28 insertions, 21 deletions
diff --git a/noncore/tools/clock/clock.cpp b/noncore/tools/clock/clock.cpp index 9898332..0eb2b83 100644 --- a/noncore/tools/clock/clock.cpp +++ b/noncore/tools/clock/clock.cpp | |||
@@ -220,115 +220,126 @@ void Clock::updateClock() | |||
220 | if ( hour == 0 ) | 220 | if ( hour == 0 ) |
221 | hour = 12; | 221 | hour = 12; |
222 | if ( hour > 12 ) | 222 | if ( hour > 12 ) |
223 | hour -= 12; | 223 | hour -= 12; |
224 | s.sprintf( "%2d%c%02d", hour, ':', tm.minute() ); | 224 | s.sprintf( "%2d%c%02d", hour, ':', tm.minute() ); |
225 | ampmLabel->setText( ( tm.hour() >= 12 ) ? "PM" : "AM" ); | 225 | ampmLabel->setText( ( tm.hour() >= 12 ) ? "PM" : "AM" ); |
226 | ampmLabel->show(); | 226 | ampmLabel->show(); |
227 | } | 227 | } |
228 | else | 228 | else |
229 | { | 229 | { |
230 | s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() ); | 230 | s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() ); |
231 | ampmLabel->hide(); | 231 | ampmLabel->hide(); |
232 | } | 232 | } |
233 | lcd->display( s ); | 233 | lcd->display( s ); |
234 | lcd->repaint( FALSE ); | 234 | lcd->repaint( FALSE ); |
235 | aclock->display( QTime::currentTime() ); | 235 | aclock->display( QTime::currentTime() ); |
236 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); | 236 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); |
237 | } | 237 | } |
238 | else | 238 | else |
239 | { | 239 | { |
240 | QTime swatch_time; | 240 | QTime swatch_time; |
241 | QString lcdtext; | 241 | QString lcdtext; |
242 | int totalms = swatch_totalms; | 242 | int totalms = swatch_totalms; |
243 | if ( swatch_running ) | 243 | if ( swatch_running ) |
244 | totalms += swatch_start.elapsed(); | 244 | totalms += swatch_start.elapsed(); |
245 | swatch_time = QTime( 0, 0, 0 ).addMSecs( totalms ); | 245 | swatch_time = QTime( 0, 0, 0 ).addMSecs( totalms ); |
246 | QString d = swatch_running ? QString( " " ) | 246 | QString d = swatch_running ? QString( " " ) |
247 | : QString::number( totalms % 1000 + 1000 ); | 247 | : QString::number( totalms % 1000 + 1000 ); |
248 | lcdtext = swatch_time.toString() + "." + d.right( 3 ).left( sw_prec ); | 248 | lcdtext = swatch_time.toString() + "." + d.right( 3 ).left( sw_prec ); |
249 | lcd->display( lcdtext ); | 249 | lcd->display( lcdtext ); |
250 | lcd->repaint( FALSE ); | 250 | lcd->repaint( FALSE ); |
251 | aclock->display( swatch_time ); | 251 | aclock->display( swatch_time ); |
252 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); | 252 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); |
253 | } | 253 | } |
254 | } | 254 | } |
255 | 255 | ||
256 | void Clock::changeClock( bool a ) | 256 | void Clock::changeClock( bool a ) |
257 | { | 257 | { |
258 | ampm = a; | 258 | ampm = a; |
259 | updateClock(); | 259 | updateClock(); |
260 | } | 260 | } |
261 | 261 | ||
262 | void Clock::clearClock( void ) | 262 | void Clock::clearClock( void ) |
263 | { | 263 | { |
264 | lcd->display( QTime( 0, 0, 0 ).toString() ); | 264 | lcd->display( QTime( 0, 0, 0 ).toString() ); |
265 | aclock->display( QTime( 0, 0, 0 ) ); | 265 | aclock->display( QTime( 0, 0, 0 ) ); |
266 | } | 266 | } |
267 | 267 | ||
268 | void Clock::startSWatch() | ||
269 | { | ||
270 | swatch_start.start(); | ||
271 | set->setText( tr( "Stop" ) ); | ||
272 | t->start( 1000 ); | ||
273 | swatch_running = TRUE; | ||
274 | // disable screensaver while stop watch is running | ||
275 | toggleScreenSaver( FALSE ); | ||
276 | } | ||
277 | |||
278 | void Clock::stopSWatch() | ||
279 | { | ||
280 | swatch_totalms += swatch_start.elapsed(); | ||
281 | set->setText( tr( "Start" ) ); | ||
282 | t->stop(); | ||
283 | swatch_running = FALSE; | ||
284 | toggleScreenSaver( TRUE ); | ||
285 | updateClock(); | ||
286 | } | ||
287 | |||
288 | |||
268 | void Clock::slotSet() | 289 | void Clock::slotSet() |
269 | { | 290 | { |
270 | if ( t->isActive() ) | 291 | if ( t->isActive() ) |
271 | { | 292 | { |
272 | swatch_totalms += swatch_start.elapsed(); | 293 | startSWatch(); |
273 | set->setText( tr( "Start" ) ); | ||
274 | t->stop(); | ||
275 | swatch_running = FALSE; | ||
276 | toggleScreenSaver( TRUE ); | ||
277 | updateClock(); | ||
278 | } | 294 | } |
279 | else | 295 | else |
280 | { | 296 | { |
281 | swatch_start.start(); | 297 | stopSWatch(); |
282 | set->setText( tr( "Stop" ) ); | ||
283 | t->start( 1000 ); | ||
284 | swatch_running = TRUE; | ||
285 | // disable screensaver while stop watch is running | ||
286 | toggleScreenSaver( FALSE ); | ||
287 | } | 298 | } |
288 | } | 299 | } |
289 | 300 | ||
290 | void Clock::slotReset() | 301 | void Clock::slotReset() |
291 | { | 302 | { |
292 | t->stop(); | 303 | t->stop(); |
293 | swatch_start.start(); | 304 | swatch_start.start(); |
294 | swatch_totalms = 0; | 305 | swatch_totalms = 0; |
295 | 306 | ||
296 | if ( swatch_running ) | 307 | if ( swatch_running ) |
297 | t->start( 1000 ); | 308 | t->start( 1000 ); |
298 | 309 | ||
299 | updateClock(); | 310 | updateClock(); |
300 | } | 311 | } |
301 | 312 | ||
302 | void Clock::modeSelect( int m ) | 313 | void Clock::modeSelect( int m ) |
303 | { | 314 | { |
304 | qDebug("Clock::modeSelect( %d) ", m); | 315 | qDebug("Clock::modeSelect( %d) ", m); |
305 | if ( m ) | 316 | if ( m ) |
306 | { | 317 | { |
307 | lcd->setNumDigits( 8 + 1 + sw_prec ); | 318 | lcd->setNumDigits( 8 + 1 + sw_prec ); |
308 | lcd->setMinimumWidth( lcd->sizeHint().width() ); | 319 | lcd->setMinimumWidth( lcd->sizeHint().width() ); |
309 | set->setEnabled( TRUE ); | 320 | set->setEnabled( TRUE ); |
310 | reset->setEnabled( TRUE ); | 321 | reset->setEnabled( TRUE ); |
311 | ampmLabel->hide(); | 322 | ampmLabel->hide(); |
312 | 323 | ||
313 | if ( !swatch_running ) | 324 | if ( !swatch_running ) |
314 | t->stop(); | 325 | t->stop(); |
315 | } | 326 | } |
316 | else | 327 | else |
317 | { | 328 | { |
318 | lcd->setNumDigits( 5 ); | 329 | lcd->setNumDigits( 5 ); |
319 | lcd->setMinimumWidth( lcd->sizeHint().width() ); | 330 | lcd->setMinimumWidth( lcd->sizeHint().width() ); |
320 | set->setEnabled( FALSE ); | 331 | set->setEnabled( FALSE ); |
321 | reset->setEnabled( FALSE ); | 332 | reset->setEnabled( FALSE ); |
322 | t->start( 1000 ); | 333 | t->start( 1000 ); |
323 | } | 334 | } |
324 | 335 | ||
325 | Config config( "Clock" ); | 336 | Config config( "Clock" ); |
326 | config.setGroup( "Mode" ); | 337 | config.setGroup( "Mode" ); |
327 | config.writeEntry( "clockMode", m ); | 338 | config.writeEntry( "clockMode", m ); |
328 | updateClock(); | 339 | updateClock(); |
329 | } | 340 | } |
330 | 341 | ||
331 | //this sets the alarm time | 342 | //this sets the alarm time |
332 | void Clock::slotSetAlarm() | 343 | void Clock::slotSetAlarm() |
333 | { | 344 | { |
334 | if ( !snoozeBtn->isHidden() ) | 345 | if ( !snoozeBtn->isHidden() ) |
@@ -556,80 +567,74 @@ void AnalogClock::drawPointers ( QPainter *p, const QRect &r, const QColor &c, c | |||
556 | h2 = rotate( center, h2, 30 * ( t.hour() % 12 ) + t.minute() / 2 ); | 567 | h2 = rotate( center, h2, 30 * ( t.hour() % 12 ) + t.minute() / 2 ); |
557 | p-> setPen ( QPen ( c, 3 )); | 568 | p-> setPen ( QPen ( c, 3 )); |
558 | p-> drawLine ( h1, h2 ); | 569 | p-> drawLine ( h1, h2 ); |
559 | } | 570 | } |
560 | 571 | ||
561 | if ( !t2 || ( t. minute ( ) != t2-> minute ( ))) { | 572 | if ( !t2 || ( t. minute ( ) != t2-> minute ( ))) { |
562 | // draw minute pointer | 573 | // draw minute pointer |
563 | m1 = rotate( center, m1, t.minute() * 6 ); | 574 | m1 = rotate( center, m1, t.minute() * 6 ); |
564 | m2 = rotate( center, m2, t.minute() * 6 ); | 575 | m2 = rotate( center, m2, t.minute() * 6 ); |
565 | p-> setPen ( QPen ( c, 2 )); | 576 | p-> setPen ( QPen ( c, 2 )); |
566 | p-> drawLine ( m1, m2 ); | 577 | p-> drawLine ( m1, m2 ); |
567 | } | 578 | } |
568 | 579 | ||
569 | if ( !t2 || ( t. second ( ) != t2-> second ( ))) { | 580 | if ( !t2 || ( t. second ( ) != t2-> second ( ))) { |
570 | // draw second pointer | 581 | // draw second pointer |
571 | s1 = rotate( center, s1, t.second() * 6 ); | 582 | s1 = rotate( center, s1, t.second() * 6 ); |
572 | s2 = rotate( center, s2, t.second() * 6 ); | 583 | s2 = rotate( center, s2, t.second() * 6 ); |
573 | p-> setPen ( QPen ( c, 1 )); | 584 | p-> setPen ( QPen ( c, 1 )); |
574 | p-> drawLine ( s1, s2 ); | 585 | p-> drawLine ( s1, s2 ); |
575 | } | 586 | } |
576 | } | 587 | } |
577 | 588 | ||
578 | void AnalogClock::display( const QTime& t ) | 589 | void AnalogClock::display( const QTime& t ) |
579 | { | 590 | { |
580 | currTime = t; | 591 | currTime = t; |
581 | clear = false; | 592 | clear = false; |
582 | repaint( false ); | 593 | repaint( false ); |
583 | clear = true; | 594 | clear = true; |
584 | } | 595 | } |
585 | 596 | ||
586 | QPoint AnalogClock::rotate( QPoint c, QPoint p, int a ) | 597 | QPoint AnalogClock::rotate( QPoint c, QPoint p, int a ) |
587 | { | 598 | { |
588 | double angle = deg2rad * ( - a + 180 ); | 599 | double angle = deg2rad * ( - a + 180 ); |
589 | double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) - | 600 | double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) - |
590 | ( p.y() - c.y() ) * sin( angle ); | 601 | ( p.y() - c.y() ) * sin( angle ); |
591 | double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) + | 602 | double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) + |
592 | ( p.x() - c.x() ) * sin( angle ); | 603 | ( p.x() - c.x() ) * sin( angle ); |
593 | return QPoint( nx, ny ); | 604 | return QPoint( nx, ny ); |
594 | } | 605 | } |
595 | 606 | ||
596 | void Clock::slotAdjustTime() | 607 | void Clock::slotAdjustTime() |
597 | { | 608 | { |
598 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 609 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
599 | e << QString( "systemtime" ); | 610 | e << QString( "systemtime" ); |
600 | } | 611 | } |
601 | 612 | ||
602 | void Clock::slotStartTimer() | 613 | void Clock::slotStartTimer() |
603 | { | 614 | { |
604 | Config cfg( "Clock" ); | ||
605 | cfg.setGroup( "Mode" ); | ||
606 | int mode = cfg.readBoolEntry( "clockMode"); | ||
607 | if ( clockRB->isChecked() ) | 615 | if ( clockRB->isChecked() ) |
608 | setSwatchMode( 1); | 616 | setSwatchMode( 1); |
609 | slotSet(); | 617 | startSWatch(); |
610 | } | 618 | } |
611 | 619 | ||
612 | void Clock::slotStopTimer() | 620 | void Clock::slotStopTimer() |
613 | { | 621 | { |
614 | Config cfg( "Clock" ); | ||
615 | cfg.setGroup( "Mode" ); | ||
616 | int mode = cfg.readBoolEntry( "clockMode"); | ||
617 | if ( clockRB->isChecked() ) | 622 | if ( clockRB->isChecked() ) |
618 | setSwatchMode( 1); | 623 | setSwatchMode( 1); |
619 | slotSet(); | 624 | stopSWatch(); |
620 | } | 625 | } |
621 | 626 | ||
622 | void Clock::slotResetTimer() | 627 | void Clock::slotResetTimer() |
623 | { | 628 | { |
624 | if ( clockRB->isChecked() ) | 629 | if ( clockRB->isChecked() ) |
625 | setSwatchMode( 1); | 630 | setSwatchMode( 1); |
626 | slotReset(); | 631 | slotReset(); |
627 | } | 632 | } |
628 | 633 | ||
629 | void Clock::setSwatchMode(int mode) | 634 | void Clock::setSwatchMode(int mode) |
630 | { | 635 | { |
631 | qDebug("Clock::setSwatchMode( %d)"), mode; | 636 | qDebug("Clock::setSwatchMode( %d)", mode); |
632 | swatchRB->setChecked( mode); | 637 | swatchRB->setChecked( mode); |
633 | clearClock( ); | 638 | clearClock( ); |
634 | modeSelect( mode ); | 639 | modeSelect( mode ); |
635 | } | 640 | } |
diff --git a/noncore/tools/clock/clock.h b/noncore/tools/clock/clock.h index 9b00e28..1e5aa2c 100644 --- a/noncore/tools/clock/clock.h +++ b/noncore/tools/clock/clock.h | |||
@@ -55,52 +55,54 @@ private: | |||
55 | void drawPointers ( QPainter *, const QRect &r, const QColor &c, const QTime &t, const QTime *t2 = 0 ); | 55 | void drawPointers ( QPainter *, const QRect &r, const QColor &c, const QTime &t, const QTime *t2 = 0 ); |
56 | 56 | ||
57 | }; | 57 | }; |
58 | 58 | ||
59 | class Clock : public QVBox | 59 | class Clock : public QVBox |
60 | { | 60 | { |
61 | Q_OBJECT | 61 | Q_OBJECT |
62 | 62 | ||
63 | public: | 63 | public: |
64 | Clock( QWidget * parent = 0, const char * name = 0, WFlags f=0 ); | 64 | Clock( QWidget * parent = 0, const char * name = 0, WFlags f=0 ); |
65 | ~Clock(); | 65 | ~Clock(); |
66 | QDateTime when; | 66 | QDateTime when; |
67 | bool bSound; | 67 | bool bSound; |
68 | int hour, minute, snoozeTime; | 68 | int hour, minute, snoozeTime; |
69 | private slots: | 69 | private slots: |
70 | void slotSet(); | 70 | void slotSet(); |
71 | void slotReset(); | 71 | void slotReset(); |
72 | void modeSelect(int); | 72 | void modeSelect(int); |
73 | void updateClock(); | 73 | void updateClock(); |
74 | void changeClock( bool ); | 74 | void changeClock( bool ); |
75 | void slotSetAlarm(); | 75 | void slotSetAlarm(); |
76 | void slotSnooze(); | 76 | void slotSnooze(); |
77 | void slotToggleAlarm(); | 77 | void slotToggleAlarm(); |
78 | void alarmOn(); | 78 | void alarmOn(); |
79 | void alarmOff(); | 79 | void alarmOff(); |
80 | void appMessage(const QCString& msg, const QByteArray& data); | 80 | void appMessage(const QCString& msg, const QByteArray& data); |
81 | void timerEvent( QTimerEvent *e ); | 81 | void timerEvent( QTimerEvent *e ); |
82 | void slotAdjustTime(); | 82 | void slotAdjustTime(); |
83 | 83 | ||
84 | void slotStartTimer(); | 84 | void slotStartTimer(); |
85 | void slotStopTimer(); | 85 | void slotStopTimer(); |
86 | void slotResetTimer(); | 86 | void slotResetTimer(); |
87 | void setSwatchMode( int ); | 87 | void setSwatchMode( int ); |
88 | private: | 88 | private: |
89 | bool alarmBool; | 89 | bool alarmBool; |
90 | QTimer *t; | 90 | QTimer *t; |
91 | QLCDNumber *lcd; | 91 | QLCDNumber *lcd; |
92 | QLabel *date; | 92 | QLabel *date; |
93 | QLabel *ampmLabel; | 93 | QLabel *ampmLabel; |
94 | QPushButton *set, *reset, *alarmBtn, *snoozeBtn, *alarmOffBtn; | 94 | QPushButton *set, *reset, *alarmBtn, *snoozeBtn, *alarmOffBtn; |
95 | QRadioButton *clockRB, *swatchRB; | 95 | QRadioButton *clockRB, *swatchRB; |
96 | AnalogClock *aclock; | 96 | AnalogClock *aclock; |
97 | QTime swatch_start; | 97 | QTime swatch_start; |
98 | int swatch_totalms; | 98 | int swatch_totalms; |
99 | bool swatch_running; | 99 | bool swatch_running; |
100 | bool ampm; | 100 | bool ampm; |
101 | void clearClock(); | 101 | void clearClock(); |
102 | void clearTimer(); | 102 | void clearTimer(); |
103 | void startSWatch(); | ||
104 | void stopSWatch(); | ||
103 | }; | 105 | }; |
104 | 106 | ||
105 | #endif | 107 | #endif |
106 | 108 | ||