summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/clock/clock.cpp255
1 files changed, 124 insertions, 131 deletions
diff --git a/noncore/tools/clock/clock.cpp b/noncore/tools/clock/clock.cpp
index ea8e8ca..a85cc19 100644
--- a/noncore/tools/clock/clock.cpp
+++ b/noncore/tools/clock/clock.cpp
@@ -1,20 +1,21 @@
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// code added and Copyright (C) by L. J. Potter <ljp@llornkcor.com> 2002
20 21
@@ -33,4 +34,2 @@
33 34
34#include <opie/oclickablelabel.h>
35
36#include <qlcdnumber.h> 35#include <qlcdnumber.h>
@@ -59,3 +58,3 @@ static void toggleScreenSaver( bool on )
59Clock::Clock( QWidget * parent, const char * name, WFlags f ) 58Clock::Clock( QWidget * parent, const char * name, WFlags f )
60 : QVBox( parent, name , f ) 59 : QVBox( parent, name , f )
61{ 60{
@@ -96,3 +95,3 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
96 QWidget *controls = new QWidget( this ); 95 QWidget *controls = new QWidget( this );
97 QGridLayout *gl = new QGridLayout( controls, 3, 2, 6, 4 ); 96 QGridLayout *gl = new QGridLayout( controls, 2, 2, 6, 4 );
98 97
@@ -135,7 +134,2 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
135 134
136 OClickableLabel *click = new OClickableLabel(controls, "label" );
137 click->setText(tr("Set date and time." ) );
138 gl->addMultiCellWidget( click, 3, 3, 0, 2, AlignHCenter);
139 connect( click, SIGNAL(clicked() ), this, SLOT(slotAdjustTime() ) );
140
141 connect( set, SIGNAL( pressed() ), SLOT( slotSet() ) ); 135 connect( set, SIGNAL( pressed() ), SLOT( slotSet() ) );
@@ -148,3 +142,3 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
148 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), 142 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)),
149 this, SLOT(appMessage(const QCString&, const QByteArray&)) ); 143 this, SLOT(appMessage(const QCString&, const QByteArray&)) );
150 144
@@ -176,3 +170,3 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
176 } 170 }
177 171
178 QTimer::singleShot( 0, this, SLOT(updateClock()) ); 172 QTimer::singleShot( 0, this, SLOT(updateClock()) );
@@ -189,35 +183,35 @@ void Clock::updateClock()
189 if ( clockRB->isChecked() ) { 183 if ( clockRB->isChecked() ) {
190 QTime tm = QDateTime::currentDateTime().time(); 184 QTime tm = QDateTime::currentDateTime().time();
191 QString s; 185 QString s;
192 if ( ampm ) { 186 if ( ampm ) {
193 int hour = tm.hour(); 187 int hour = tm.hour();
194 if (hour == 0) 188 if (hour == 0)
195 hour = 12; 189 hour = 12;
196 if (hour > 12) 190 if (hour > 12)
197 hour -= 12; 191 hour -= 12;
198 s.sprintf( "%2d%c%02d", hour, ':', tm.minute() ); 192 s.sprintf( "%2d%c%02d", hour, ':', tm.minute() );
199 ampmLabel->setText( (tm.hour() >= 12) ? "PM" : "AM" ); 193 ampmLabel->setText( (tm.hour() >= 12) ? "PM" : "AM" );
200 ampmLabel->show(); 194 ampmLabel->show();
201 } else { 195 } else {
202 s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() ); 196 s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() );
203 ampmLabel->hide(); 197 ampmLabel->hide();
204 } 198 }
205 lcd->display( s ); 199 lcd->display( s );
206 lcd->repaint( FALSE ); 200 lcd->repaint( FALSE );
207 aclock->display( QTime::currentTime() ); 201 aclock->display( QTime::currentTime() );
208 date->setText( TimeString::longDateString( QDate::currentDate() ) ); 202 date->setText( TimeString::longDateString( QDate::currentDate() ) );
209 } else { 203 } else {
210 QTime swatch_time; 204 QTime swatch_time;
211 QString lcdtext; 205 QString lcdtext;
212 int totalms = swatch_totalms; 206 int totalms = swatch_totalms;
213 if ( swatch_running ) 207 if ( swatch_running )
214 totalms += swatch_start.elapsed(); 208 totalms += swatch_start.elapsed();
215 swatch_time = QTime(0,0,0).addMSecs(totalms); 209 swatch_time = QTime(0,0,0).addMSecs(totalms);
216 QString d = swatch_running ? QString(" ") 210 QString d = swatch_running ? QString(" ")
217 : QString::number(totalms%1000+1000); 211 : QString::number(totalms%1000+1000);
218 lcdtext = swatch_time.toString() + "." + d.right(3).left(sw_prec); 212 lcdtext = swatch_time.toString() + "." + d.right(3).left(sw_prec);
219 lcd->display( lcdtext ); 213 lcd->display( lcdtext );
220 lcd->repaint( FALSE ); 214 lcd->repaint( FALSE );
221 aclock->display( swatch_time ); 215 aclock->display( swatch_time );
222 date->setText( TimeString::longDateString( QDate::currentDate() ) ); 216 date->setText( TimeString::longDateString( QDate::currentDate() ) );
223 } 217 }
@@ -240,15 +234,15 @@ void Clock::slotSet()
240 if ( t->isActive() ) { 234 if ( t->isActive() ) {
241 swatch_totalms += swatch_start.elapsed(); 235 swatch_totalms += swatch_start.elapsed();
242 set->setText( tr( "Start" ) ); 236 set->setText( tr( "Start" ) );
243 t->stop(); 237 t->stop();
244 swatch_running = FALSE; 238 swatch_running = FALSE;
245 toggleScreenSaver( TRUE ); 239 toggleScreenSaver( TRUE );
246 updateClock(); 240 updateClock();
247 } else { 241 } else {
248 swatch_start.start(); 242 swatch_start.start();
249 set->setText( tr( "Stop" ) ); 243 set->setText( tr( "Stop" ) );
250 t->start( 1000 ); 244 t->start( 1000 );
251 swatch_running = TRUE; 245 swatch_running = TRUE;
252 // disable screensaver while stop watch is running 246 // disable screensaver while stop watch is running
253 toggleScreenSaver( FALSE ); 247 toggleScreenSaver( FALSE );
254 } 248 }
@@ -263,3 +257,3 @@ void Clock::slotReset()
263 if (swatch_running ) 257 if (swatch_running )
264 t->start(1000); 258 t->start(1000);
265 259
@@ -271,16 +265,16 @@ void Clock::modeSelect( int m )
271 if ( m ) { 265 if ( m ) {
272 lcd->setNumDigits( 8+1+sw_prec ); 266 lcd->setNumDigits( 8+1+sw_prec );
273 lcd->setMinimumWidth( lcd->sizeHint().width() ); 267 lcd->setMinimumWidth( lcd->sizeHint().width() );
274 set->setEnabled( TRUE ); 268 set->setEnabled( TRUE );
275 reset->setEnabled( TRUE ); 269 reset->setEnabled( TRUE );
276 ampmLabel->hide(); 270 ampmLabel->hide();
277 271
278 if ( !swatch_running ) 272 if ( !swatch_running )
279 t->stop(); 273 t->stop();
280 } else { 274 } else {
281 lcd->setNumDigits( 5 ); 275 lcd->setNumDigits( 5 );
282 lcd->setMinimumWidth( lcd->sizeHint().width() ); 276 lcd->setMinimumWidth( lcd->sizeHint().width() );
283 set->setEnabled( FALSE ); 277 set->setEnabled( FALSE );
284 reset->setEnabled( FALSE ); 278 reset->setEnabled( FALSE );
285 t->start(1000); 279 t->start(1000);
286 } 280 }
@@ -290,3 +284,3 @@ void Clock::modeSelect( int m )
290//this sets the alarm time 284//this sets the alarm time
291void Clock::slotSetAlarm() 285void Clock::slotSetAlarm()
292{ 286{
@@ -312,3 +306,3 @@ void Clock::slotSetAlarm()
312 config.write(); 306 config.write();
313 } 307 }
314} 308}
@@ -323,4 +317,4 @@ void Clock::slotSnooze()
323 AlarmServer::addAlarm( when, 317 AlarmServer::addAlarm( when,
324 "QPE/Application/clock", 318 "QPE/Application/clock",
325 "alarm(QDateTime,int)", warn ); 319 "alarm(QDateTime,int)", warn );
326 320
@@ -329,3 +323,3 @@ void Clock::slotSnooze()
329//toggles alarm on/off 323//toggles alarm on/off
330void Clock::slotToggleAlarm() 324void Clock::slotToggleAlarm()
331{ 325{
@@ -360,6 +354,6 @@ void Clock::alarmOn()
360 when=whenl; 354 when=whenl;
361 AlarmServer::addAlarm( when, 355 AlarmServer::addAlarm( when,
362 "QPE/Application/clock", 356 "QPE/Application/clock",
363 "alarm(QDateTime,int)", warn ); 357 "alarm(QDateTime,int)", warn );
364 QMessageBox::message("Note","Alarm is set for:\n"+ whenl.toString()); 358 setCaption("Alarm set: "+ whenl.toString());
365} 359}
@@ -370,7 +364,7 @@ void Clock::alarmOff()
370 bSound=FALSE; 364 bSound=FALSE;
371 AlarmServer::deleteAlarm( when, 365 AlarmServer::deleteAlarm( when,
372 "QPE/Application/clock", 366 "QPE/Application/clock",
373 "alarm(QDateTime,int)", warn ); 367 "alarm(QDateTime,int)", warn );
374 qDebug("Alarm Off "+ when.toString()); 368 qDebug("Alarm Off "+ when.toString());
375 369 setCaption("Clock");
376} 370}
@@ -382,6 +376,6 @@ void Clock::appMessage(const QCString& msg, const QByteArray& data)
382 bSound=TRUE; 376 bSound=TRUE;
383 if ( msg == "alarm(QDateTime,int)" ) { 377 if ( msg == "alarm(QDateTime,int)" ) {
384 Sound::soundAlarm(); 378 Sound::soundAlarm();
385 stopTimer = startTimer( timerStay); 379 stopTimer = startTimer( timerStay);
386 } 380 }
387} 381}
@@ -391,3 +385,3 @@ void Clock::timerEvent( QTimerEvent *e )
391 static int stop = 0; 385 static int stop = 0;
392 if ( stop < 10 && bSound) { 386 if ( stop < 120 && bSound) {
393 Sound::soundAlarm(); 387 Sound::soundAlarm();
@@ -397,2 +391,6 @@ void Clock::timerEvent( QTimerEvent *e )
397 killTimer( e->timerId() ); 391 killTimer( e->timerId() );
392 alarmOffBtn->setText( tr( "Alarm Is Off" ) );
393 alarmBool=FALSE;
394 snoozeBtn->hide();
395 setCaption("Clock: Alarm was missed.");
398 } 396 }
@@ -427,4 +425,4 @@ void AnalogClock::drawContents( QPainter *p )
427 if ( clear && prevTime.secsTo(currTime) > 1 ) { 425 if ( clear && prevTime.secsTo(currTime) > 1 ) {
428 p->eraseRect( rect() ); 426 p->eraseRect( rect() );
429 return; 427 return;
430 } 428 }
@@ -432,6 +430,6 @@ void AnalogClock::drawContents( QPainter *p )
432 if ( !clear ) { 430 if ( !clear ) {
433 // draw ticks 431 // draw ticks
434 p->setPen( QPen( color, 1 ) ); 432 p->setPen( QPen( color, 1 ) );
435 for ( int i = 0; i < 12; i++ ) 433 for ( int i = 0; i < 12; i++ )
436 p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) ); 434 p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) );
437 } 435 }
@@ -439,8 +437,8 @@ void AnalogClock::drawContents( QPainter *p )
439 if ( !clear || prevTime.minute() != currTime.minute() || 437 if ( !clear || prevTime.minute() != currTime.minute() ||
440 prevTime.hour() != currTime.hour() ) { 438 prevTime.hour() != currTime.hour() ) {
441 // draw hour pointer 439 // draw hour pointer
442 h1 = rotate( center, h1, 30 * ( time.hour() % 12 ) + time.minute() / 2 ); 440 h1 = rotate( center, h1, 30 * ( time.hour() % 12 ) + time.minute() / 2 );
443 h2 = rotate( center, h2, 30 * ( time.hour() % 12 ) + time.minute() / 2 ); 441 h2 = rotate( center, h2, 30 * ( time.hour() % 12 ) + time.minute() / 2 );
444 p->setPen( QPen( color, 3 ) ); 442 p->setPen( QPen( color, 3 ) );
445 p->drawLine( h1, h2 ); 443 p->drawLine( h1, h2 );
446 } 444 }
@@ -448,10 +446,10 @@ void AnalogClock::drawContents( QPainter *p )
448 if ( !clear || prevTime.minute() != currTime.minute() ) { 446 if ( !clear || prevTime.minute() != currTime.minute() ) {
449 // draw minute pointer 447 // draw minute pointer
450 m1 = rotate( center, m1, time.minute() * 6 ); 448 m1 = rotate( center, m1, time.minute() * 6 );
451 m2 = rotate( center, m2, time.minute() * 6 ); 449 m2 = rotate( center, m2, time.minute() * 6 );
452 p->setPen( QPen( color, 2 ) ); 450 p->setPen( QPen( color, 2 ) );
453 p->drawLine( m1, m2 ); 451 p->drawLine( m1, m2 );
454 } 452 }
455 453
456 // draw second pointer 454 // draw second pointer
457 s1 = rotate( center, s1, time.second() * 6 ); 455 s1 = rotate( center, s1, time.second() * 6 );
@@ -462,3 +460,3 @@ void AnalogClock::drawContents( QPainter *p )
462 if ( !clear ) 460 if ( !clear )
463 prevTime = currTime; 461 prevTime = currTime;
464} 462}
@@ -478,11 +476,6 @@ QPoint AnalogClock::rotate( QPoint c, QPoint p, int a )
478 double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) - 476 double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) -
479 ( p.y() - c.y() ) * sin( angle ); 477 ( p.y() - c.y() ) * sin( angle );
480 double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) + 478 double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) +
481 ( p.x() - c.x() ) * sin( angle ); 479 ( p.x() - c.x() ) * sin( angle );
482 return QPoint( nx, ny ); 480 return QPoint( nx, ny );
483} 481}
484void Clock::slotAdjustTime()
485{
486 QCopEnvelope e("QPE/System", "execute(QString)");
487 e << QString("systemtime");
488}