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