summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-05-31 13:00:05 (UTC)
committer llornkcor <llornkcor>2002-05-31 13:00:05 (UTC)
commit075f2ae74f328581ec0db05d633961f3baa5ed36 (patch) (unidiff)
tree370eb2838813a9fa2aaf47e32f6e711dd2a8f36e
parentdd08e7fa2ccbcc0489c17ed305b20a9a7d187161 (diff)
downloadopie-075f2ae74f328581ec0db05d633961f3baa5ed36.zip
opie-075f2ae74f328581ec0db05d633961f3baa5ed36.tar.gz
opie-075f2ae74f328581ec0db05d633961f3baa5ed36.tar.bz2
added clock to popup if closed before app gets alarm message
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/clock/clock.cpp11
-rw-r--r--noncore/tools/clock/clock.h1
2 files changed, 9 insertions, 3 deletions
diff --git a/noncore/tools/clock/clock.cpp b/noncore/tools/clock/clock.cpp
index 0a21146..9b9e644 100644
--- a/noncore/tools/clock/clock.cpp
+++ b/noncore/tools/clock/clock.cpp
@@ -1,164 +1,166 @@
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// changes added and Copyright (C) by L. J. Potter <ljp@llornkcor.com> 2002
20 21
21#include "clock.h" 22#include "clock.h"
22#include "setAlarm.h" 23#include "setAlarm.h"
23 24
24#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
25#include <qpe/qcopenvelope_qws.h> 26#include <qpe/qcopenvelope_qws.h>
26#include <qpe/config.h> 27#include <qpe/config.h>
27#include <qpe/timestring.h> 28#include <qpe/timestring.h>
28#include <qpe/alarmserver.h> 29#include <qpe/alarmserver.h>
29#include <qpe/sound.h> 30#include <qpe/sound.h>
30#include <qpe/resource.h> 31#include <qpe/resource.h>
31#include <qsound.h> 32#include <qsound.h>
32#include <qtimer.h> 33#include <qtimer.h>
33 34
34#include <opie/oclickablelabel.h> 35#include <opie/oclickablelabel.h>
35 36
36#include <qlcdnumber.h> 37#include <qlcdnumber.h>
37#include <qslider.h> 38#include <qslider.h>
38#include <qlabel.h> 39#include <qlabel.h>
39#include <qlayout.h> 40#include <qlayout.h>
40#include <qtimer.h> 41#include <qtimer.h>
41#include <qpushbutton.h> 42#include <qpushbutton.h>
42#include <qradiobutton.h> 43#include <qradiobutton.h>
43#include <qbuttongroup.h> 44#include <qbuttongroup.h>
44#include <qpainter.h> 45#include <qpainter.h>
45#include <qmessagebox.h> 46#include <qmessagebox.h>
46#include <qdatetime.h> 47#include <qdatetime.h>
47 48
48#include <math.h> 49#include <math.h>
49 50
50const double deg2rad = 0.017453292519943295769; // pi/180 51const double deg2rad = 0.017453292519943295769; // pi/180
51const int sw_prec = 2; 52const int sw_prec = 2;
52 53
53static void toggleScreenSaver( bool on ) 54static void toggleScreenSaver( bool on )
54{ 55{
55 QCopEnvelope e("QPE/System", "setScreenSaverMode(int)" ); 56 QCopEnvelope e("QPE/System", "setScreenSaverMode(int)" );
56 e << (on ? QPEApplication::Enable: QPEApplication::DisableSuspend ); 57 e << (on ? QPEApplication::Enable: QPEApplication::DisableSuspend );
57} 58}
58 59
59Clock::Clock( QWidget * parent, const char * name, WFlags f ) 60Clock::Clock( QWidget * parent, const char * name, WFlags f )
60 : QVBox( parent, name , f ) 61 : QVBox( parent, name , f )
61{ 62{
62 setSpacing( 4 ); 63 setSpacing( 4 );
63 setMargin( 1 ); 64 setMargin( 1 );
64 65
65 Config config( "qpe" ); 66 Config config( "qpe" );
66 config.setGroup("Time"); 67 config.setGroup("Time");
67 ampm = config.readBoolEntry( "AMPM", TRUE ); 68 ampm = config.readBoolEntry( "AMPM", TRUE );
68 69
70
69 snoozeBtn = new QPushButton ( this); 71 snoozeBtn = new QPushButton ( this);
70 snoozeBtn->setText( tr( "Snooze" ) ); 72 snoozeBtn->setText( tr( "Snooze" ) );
71 73
72 aclock = new AnalogClock( this ); 74 aclock = new AnalogClock( this );
73 aclock->display( QTime::currentTime() ); 75 aclock->display( QTime::currentTime() );
74 aclock->setLineWidth( 2 ); 76 aclock->setLineWidth( 2 );
75 77
76 QHBox *hb = new QHBox( this ); 78 QHBox *hb = new QHBox( this );
77 hb->setMargin( 0 ); 79 hb->setMargin( 0 );
78 QWidget *space = new QWidget( hb ); 80 QWidget *space = new QWidget( hb );
79 lcd = new QLCDNumber( hb ); 81 lcd = new QLCDNumber( hb );
80 lcd->setSegmentStyle( QLCDNumber::Flat ); 82 lcd->setSegmentStyle( QLCDNumber::Flat );
81 lcd->setFrameStyle( QFrame::NoFrame ); 83 lcd->setFrameStyle( QFrame::NoFrame );
82 lcd->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) ); 84 lcd->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) );
83 lcd->setFixedHeight( 23 ); 85 lcd->setFixedHeight( 23 );
84 86
85 ampmLabel = new QLabel( tr("PM"), hb ); 87 ampmLabel = new QLabel( tr("PM"), hb );
86 ampmLabel->setFont( QFont( "Helvetica", 14, QFont::Bold ) ); 88 ampmLabel->setFont( QFont( "Helvetica", 14, QFont::Bold ) );
87 ampmLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred ) ); 89 ampmLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred ) );
88 ampmLabel->setAlignment( AlignLeft | AlignBottom ); 90 ampmLabel->setAlignment( AlignLeft | AlignBottom );
89 space = new QWidget( hb ); 91 space = new QWidget( hb );
90 92
91 date = new QLabel( this ); 93 date = new QLabel( this );
92 date->setAlignment( AlignHCenter | AlignVCenter ); 94 date->setAlignment( AlignHCenter | AlignVCenter );
93 date->setFont( QFont( "Helvetica", 14, QFont::Bold ) ); 95 date->setFont( QFont( "Helvetica", 14, QFont::Bold ) );
94 date->setText( TimeString::longDateString( QDate::currentDate() ) ); 96 date->setText( TimeString::longDateString( QDate::currentDate() ) );
95 97
96 QWidget *controls = new QWidget( this ); 98 QWidget *controls = new QWidget( this );
97 QGridLayout *gl = new QGridLayout( controls, 3, 2, 6, 4 ); 99 QGridLayout *gl = new QGridLayout( controls, 3, 2, 6, 4 );
98 100
99 QButtonGroup *grp = new QButtonGroup( controls ); 101 QButtonGroup *grp = new QButtonGroup( controls );
100 grp->setRadioButtonExclusive( true ); 102 grp->setRadioButtonExclusive( true );
101 grp->hide(); 103 grp->hide();
102 104
103 clockRB = new QRadioButton ( tr( "Clock" ), controls ); 105 clockRB = new QRadioButton ( tr( "Clock" ), controls );
104 gl->addWidget( clockRB, 0, 0 ); 106 gl->addWidget( clockRB, 0, 0 );
105 grp->insert( clockRB ); 107 grp->insert( clockRB );
106 108
107 swatchRB = new QRadioButton ( tr( "Stopwatch" ), controls ); 109 swatchRB = new QRadioButton ( tr( "Stopwatch" ), controls );
108 gl->addWidget( swatchRB, 1, 0 ); 110 gl->addWidget( swatchRB, 1, 0 );
109 grp->insert( swatchRB ); 111 grp->insert( swatchRB );
110 112
111 connect( grp, SIGNAL(clicked(int)), this, SLOT(modeSelect(int)) ); 113 connect( grp, SIGNAL(clicked(int)), this, SLOT(modeSelect(int)) );
112 grp->setButton( 0 ); 114 grp->setButton( 0 );
113 115
114 set = new QPushButton ( controls ); 116 set = new QPushButton ( controls );
115 set->setMaximumSize(50,30); 117 set->setMaximumSize(50,30);
116 gl->addWidget( set, 0, 1 ); 118 gl->addWidget( set, 0, 1 );
117 set->setText( tr( "Start" ) ); 119 set->setText( tr( "Start" ) );
118 set->setEnabled( FALSE ); 120 set->setEnabled( FALSE );
119 grp->insert( set ); 121 grp->insert( set );
120 122
121 reset = new QPushButton ( controls ); 123 reset = new QPushButton ( controls );
122 gl->addWidget( reset, 1, 1 ); 124 gl->addWidget( reset, 1, 1 );
123 reset->setText( tr( "Reset" ) ); 125 reset->setText( tr( "Reset" ) );
124 reset->setEnabled( FALSE ); 126 reset->setEnabled( FALSE );
125 grp->insert( reset ); 127 grp->insert( reset );
126 128
127 alarmOffBtn = new QPushButton ( controls ); 129 alarmOffBtn = new QPushButton ( controls );
128// alarmOffBtn->setMaximumSize(60,30); 130// alarmOffBtn->setMaximumSize(60,30);
129 gl->addWidget( alarmOffBtn, 0, 2 ); 131 gl->addWidget( alarmOffBtn, 0, 2 );
130 132
131 alarmBtn = new QPushButton ( controls ); 133 alarmBtn = new QPushButton ( controls );
132 // alarmBtn->setMaximumSize(60,30); 134 // alarmBtn->setMaximumSize(60,30);
133 gl->addWidget( alarmBtn, 1, 2 ); 135 gl->addWidget( alarmBtn, 1, 2 );
134 alarmBtn->setText( tr( "Set Alarm" ) ); 136 alarmBtn->setText( tr( "Set Alarm" ) );
135 137
136 OClickableLabel *click = new OClickableLabel(controls, "label" ); 138 OClickableLabel *click = new OClickableLabel(controls, "label" );
137 click->setText(tr("Set date and time." ) ); 139 click->setText(tr("Set date and time." ) );
138 gl->addMultiCellWidget( click, 3, 3, 0, 2, AlignHCenter); 140 gl->addMultiCellWidget( click, 3, 3, 0, 2, AlignHCenter);
139 connect( click, SIGNAL(clicked() ), this, SLOT(slotAdjustTime() ) ); 141 connect( click, SIGNAL(clicked() ), this, SLOT(slotAdjustTime() ) );
140 142
141 connect( set, SIGNAL( pressed() ), SLOT( slotSet() ) ); 143 connect( set, SIGNAL( pressed() ), SLOT( slotSet() ) );
142 connect( reset, SIGNAL( clicked() ), SLOT( slotReset() ) ); 144 connect( reset, SIGNAL( clicked() ), SLOT( slotReset() ) );
143 145
144 connect( alarmBtn, SIGNAL( clicked() ), SLOT( slotSetAlarm() ) ); 146 connect( alarmBtn, SIGNAL( clicked() ), SLOT( slotSetAlarm() ) );
145 connect( snoozeBtn, SIGNAL( clicked() ), SLOT( slotSnooze() ) ); 147 connect( snoozeBtn, SIGNAL( clicked() ), SLOT( slotSnooze() ) );
146 connect( alarmOffBtn, SIGNAL( clicked() ), SLOT( slotToggleAlarm() ) ); 148 connect( alarmOffBtn, SIGNAL( clicked() ), SLOT( slotToggleAlarm() ) );
147 149
148 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), 150 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)),
149 this, SLOT(appMessage(const QCString&, const QByteArray&)) ); 151 this, SLOT(appMessage(const QCString&, const QByteArray&)) );
150 152
151 t = new QTimer( this ); 153 t = new QTimer( this );
152 connect( t, SIGNAL( timeout() ), SLOT( updateClock() ) ); 154 connect( t, SIGNAL( timeout() ), SLOT( updateClock() ) );
153 t->start( 1000 ); 155 t->start( 1000 );
154 156
155 connect( qApp, SIGNAL( timeChanged() ), SLOT( updateClock() ) ); 157 connect( qApp, SIGNAL( timeChanged() ), SLOT( updateClock() ) );
156 158
157 swatch_running = FALSE; 159 swatch_running = FALSE;
158 swatch_totalms = 0; 160 swatch_totalms = 0;
159 161
160 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) ); 162 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) );
161 163
162 QString tmp = config.readEntry("clockAlarmHour", ""); 164 QString tmp = config.readEntry("clockAlarmHour", "");
163 bool ok; 165 bool ok;
164 hour = tmp.toInt(&ok,10); 166 hour = tmp.toInt(&ok,10);
@@ -287,206 +289,211 @@ void Clock::modeSelect( int m )
287 updateClock(); 289 updateClock();
288} 290}
289 291
290//this sets the alarm time 292//this sets the alarm time
291void Clock::slotSetAlarm() 293void Clock::slotSetAlarm()
292{ 294{
293 if( !snoozeBtn->isHidden()) 295 if( !snoozeBtn->isHidden())
294 slotToggleAlarm(); 296 slotToggleAlarm();
295 Set_Alarm *setAlarmDlg; 297 Set_Alarm *setAlarmDlg;
296 setAlarmDlg = new Set_Alarm(this,"SetAlarm", TRUE); 298 setAlarmDlg = new Set_Alarm(this,"SetAlarm", TRUE);
297 int result = setAlarmDlg->exec(); 299 int result = setAlarmDlg->exec();
298 if(result == 1) { 300 if(result == 1) {
299 Config config( "qpe" ); 301 Config config( "qpe" );
300 config.setGroup("Time"); 302 config.setGroup("Time");
301 QString tmp; 303 QString tmp;
302 hour = setAlarmDlg->Hour_Slider->value(); 304 hour = setAlarmDlg->Hour_Slider->value();
303 minute = setAlarmDlg->Minute_Slider->value(); 305 minute = setAlarmDlg->Minute_Slider->value();
304 snoozeTime=setAlarmDlg->SnoozeSlider->value(); 306 snoozeTime=setAlarmDlg->SnoozeSlider->value();
305 if(ampm) { 307 if(ampm) {
306 if(setAlarmDlg->Pm_RadioButton->isChecked() && hour < 12 ) 308 if(setAlarmDlg->Pm_RadioButton->isChecked() && hour < 12 )
307 hour+=12; 309 hour+=12;
308 } 310 }
309 config.writeEntry("clockAlarmHour", tmp.setNum( hour ),10); 311 config.writeEntry("clockAlarmHour", tmp.setNum( hour ),10);
310 config.writeEntry("clockAlarmMinute",tmp.setNum( minute ),10); 312 config.writeEntry("clockAlarmMinute",tmp.setNum( minute ),10);
311 config.writeEntry("clockAlarmSnooze",tmp.setNum( snoozeTime ),10); 313 config.writeEntry("clockAlarmSnooze",tmp.setNum( snoozeTime ),10);
312 config.write(); 314 config.write();
313 } 315 }
314} 316}
315 317
316void Clock::slotSnooze() 318void Clock::slotSnooze()
317{ 319{
318 bSound=FALSE; 320 bSound=FALSE;
319 int warn = 0; 321 int warn = 0;
320 QTime t = QTime::currentTime(); 322 QTime t = QTime::currentTime();
321 QDateTime whenl( when.date(), t.addSecs( snoozeTime*60)); 323 QDateTime whenl( when.date(), t.addSecs( snoozeTime*60));
322 when=whenl; 324 when=whenl;
323 AlarmServer::addAlarm( when, 325 AlarmServer::addAlarm( when,
324 "QPE/Application/clock", 326 "QPE/Application/clock",
325 "alarm(QDateTime,int)", warn ); 327 "alarm(QDateTime,int)", warn );
326 328
327} 329}
328 330
329//toggles alarm on/off 331//toggles alarm on/off
330void Clock::slotToggleAlarm() 332void Clock::slotToggleAlarm()
331{ 333{
332 Config config( "qpe" ); 334 Config config( "qpe" );
333 config.setGroup("Time"); 335 config.setGroup("Time");
334 if(alarmBool) { 336 if(alarmBool) {
335 config.writeEntry("clockAlarmSet","FALSE"); 337 config.writeEntry("clockAlarmSet","FALSE");
336 alarmOffBtn->setText( tr( "Alarm Is Off" ) ); 338 alarmOffBtn->setText( tr( "Alarm Is Off" ) );
337 snoozeBtn->hide(); 339 snoozeBtn->hide();
338 alarmBool=FALSE; 340 alarmBool=FALSE;
339 alarmOff(); 341 alarmOff();
340 } else { 342 } else {
341 config.writeEntry("clockAlarmSet","TRUE"); 343 config.writeEntry("clockAlarmSet","TRUE");
342 alarmOffBtn->setText( tr( "Alarm Is On" ) ); 344 alarmOffBtn->setText( tr( "Alarm Is On" ) );
343 snoozeBtn->show(); 345 snoozeBtn->show();
344 alarmBool=TRUE; 346 alarmBool=TRUE;
345 alarmOn(); 347 alarmOn();
346 } 348 }
347 config.write(); 349 config.write();
348} 350}
349 351
350void Clock::alarmOn() 352void Clock::alarmOn()
351{ 353{
352 QDate d = QDate::currentDate(); 354 QDate d = QDate::currentDate();
353 QTime tm((int)hour,(int)minute,0); 355 QTime tm((int)hour,(int)minute,0);
354 qDebug("Time set "+tm.toString()); 356 qDebug("Time set "+tm.toString());
355 QTime t = QTime::currentTime(); 357 QTime t = QTime::currentTime();
356 if( t > tm) 358 if( t > tm)
357 d = d.addDays(1); 359 d = d.addDays(1);
358 int warn = 0; 360 int warn = 0;
359 QDateTime whenl(d,tm); 361 QDateTime whenl(d,tm);
360 when=whenl; 362 when=whenl;
361 AlarmServer::addAlarm( when, 363 AlarmServer::addAlarm( when,
362 "QPE/Application/clock", 364 "QPE/Application/clock",
363 "alarm(QDateTime,int)", warn ); 365 "alarm(QDateTime,int)", warn );
364 setCaption("Alarm set: "+ whenl.toString()); 366 setCaption("Alarm set: "+ whenl.toString());
365} 367}
366 368
367void Clock::alarmOff() 369void Clock::alarmOff()
368{ 370{
369 int warn = 0; 371 int warn = 0;
370 bSound=FALSE; 372 bSound=FALSE;
371 AlarmServer::deleteAlarm( when, 373 AlarmServer::deleteAlarm( when,
372 "QPE/Application/clock", 374 "QPE/Application/clock",
373 "alarm(QDateTime,int)", warn ); 375 "alarm(QDateTime,int)", warn );
374 qDebug("Alarm Off "+ when.toString()); 376 qDebug("Alarm Off "+ when.toString());
375 setCaption("Clock"); 377 setCaption("Clock");
376} 378}
377 379
378void Clock::appMessage(const QCString& msg, const QByteArray& data) 380void Clock::appMessage(const QCString& msg, const QByteArray& data)
379{ 381{
380 int stopTimer = 0; 382 int stopTimer = 0;
381 int timerStay = 5000; 383 int timerStay = 5000;
382 bSound=TRUE; 384 bSound=TRUE;
385 qDebug("Message received in clock");
383 if ( msg == "alarm(QDateTime,int)" ) { 386 if ( msg == "alarm(QDateTime,int)" ) {
384 Sound::soundAlarm(); 387 Sound::soundAlarm();
385 stopTimer = startTimer( timerStay); 388 stopTimer = startTimer( timerStay);
386 } 389 }
390 show();
391 raise();
392 QPEApplication::setKeepRunning();
393 setActiveWindow();
387} 394}
388 395
389void Clock::timerEvent( QTimerEvent *e ) 396void Clock::timerEvent( QTimerEvent *e )
390{ 397{
391 static int stop = 0; 398 static int stop = 0;
392 if ( stop < 120 && bSound) { 399 if ( stop < 120 && bSound) {
393 Sound::soundAlarm(); 400 Sound::soundAlarm();
394 stop++; 401 stop++;
395 } else { 402 } else {
396 stop = 0; 403 stop = 0;
397 killTimer( e->timerId() ); 404 killTimer( e->timerId() );
398 alarmOffBtn->setText( tr( "Alarm Is Off" ) ); 405 alarmOffBtn->setText( tr( "Alarm Is Off" ) );
399 alarmBool=FALSE; 406 alarmBool=FALSE;
400 snoozeBtn->hide(); 407 snoozeBtn->hide();
401 setCaption("Clock: Alarm was missed."); 408 setCaption("Clock: Alarm was missed.");
402 } 409 }
403} 410}
404 411
405 412
406QSizePolicy AnalogClock::sizePolicy() const 413QSizePolicy AnalogClock::sizePolicy() const
407{ 414{
408 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); 415 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
409} 416}
410 417
411void AnalogClock::drawContents( QPainter *p ) 418void AnalogClock::drawContents( QPainter *p )
412{ 419{
413 QRect r = contentsRect(); 420 QRect r = contentsRect();
414 QPoint center( r.x() + r.width() / 2, r.y() + r.height() / 2 ); 421 QPoint center( r.x() + r.width() / 2, r.y() + r.height() / 2 );
415 422
416 QPoint l1( r.x() + r.width() / 2, r.y() + 2 ); 423 QPoint l1( r.x() + r.width() / 2, r.y() + 2 );
417 QPoint l2( r.x() + r.width() / 2, r.y() + 8 ); 424 QPoint l2( r.x() + r.width() / 2, r.y() + 8 );
418 425
419 QPoint h1( r.x() + r.width() / 2, r.y() + r.height() / 4 ); 426 QPoint h1( r.x() + r.width() / 2, r.y() + r.height() / 4 );
420 QPoint h2( r.x() + r.width() / 2, r.y() + r.height() / 2 ); 427 QPoint h2( r.x() + r.width() / 2, r.y() + r.height() / 2 );
421 428
422 QPoint m1( r.x() + r.width() / 2, r.y() + r.height() / 8 ); 429 QPoint m1( r.x() + r.width() / 2, r.y() + r.height() / 8 );
423 QPoint m2( r.x() + r.width() / 2, r.y() + r.height() / 2 ); 430 QPoint m2( r.x() + r.width() / 2, r.y() + r.height() / 2 );
424 431
425 QPoint s1( r.x() + r.width() / 2, r.y() + 8 ); 432 QPoint s1( r.x() + r.width() / 2, r.y() + 8 );
426 QPoint s2( r.x() + r.width() / 2, r.y() + r.height() / 2 ); 433 QPoint s2( r.x() + r.width() / 2, r.y() + r.height() / 2 );
427 434
428 QColor color( clear ? backgroundColor() : black ); 435 QColor color( clear ? backgroundColor() : black );
429 QTime time = clear ? prevTime : currTime; 436 QTime time = clear ? prevTime : currTime;
430 437
431 if ( clear && prevTime.secsTo(currTime) > 1 ) { 438 if ( clear && prevTime.secsTo(currTime) > 1 ) {
432 p->eraseRect( rect() ); 439 p->eraseRect( rect() );
433 return; 440 return;
434 } 441 }
435 442
436 if ( !clear ) { 443 if ( !clear ) {
437 // draw ticks 444 // draw ticks
438 p->setPen( QPen( color, 1 ) ); 445 p->setPen( QPen( color, 1 ) );
439 for ( int i = 0; i < 12; i++ ) 446 for ( int i = 0; i < 12; i++ )
440 p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) ); 447 p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) );
441 } 448 }
442 449
443 if ( !clear || prevTime.minute() != currTime.minute() || 450 if ( !clear || prevTime.minute() != currTime.minute() ||
444 prevTime.hour() != currTime.hour() ) { 451 prevTime.hour() != currTime.hour() ) {
445 // draw hour pointer 452 // draw hour pointer
446 h1 = rotate( center, h1, 30 * ( time.hour() % 12 ) + time.minute() / 2 ); 453 h1 = rotate( center, h1, 30 * ( time.hour() % 12 ) + time.minute() / 2 );
447 h2 = rotate( center, h2, 30 * ( time.hour() % 12 ) + time.minute() / 2 ); 454 h2 = rotate( center, h2, 30 * ( time.hour() % 12 ) + time.minute() / 2 );
448 p->setPen( QPen( color, 3 ) ); 455 p->setPen( QPen( color, 3 ) );
449 p->drawLine( h1, h2 ); 456 p->drawLine( h1, h2 );
450 } 457 }
451 458
452 if ( !clear || prevTime.minute() != currTime.minute() ) { 459 if ( !clear || prevTime.minute() != currTime.minute() ) {
453 // draw minute pointer 460 // draw minute pointer
454 m1 = rotate( center, m1, time.minute() * 6 ); 461 m1 = rotate( center, m1, time.minute() * 6 );
455 m2 = rotate( center, m2, time.minute() * 6 ); 462 m2 = rotate( center, m2, time.minute() * 6 );
456 p->setPen( QPen( color, 2 ) ); 463 p->setPen( QPen( color, 2 ) );
457 p->drawLine( m1, m2 ); 464 p->drawLine( m1, m2 );
458 } 465 }
459 466
460 // draw second pointer 467 // draw second pointer
461 s1 = rotate( center, s1, time.second() * 6 ); 468 s1 = rotate( center, s1, time.second() * 6 );
462 s2 = rotate( center, s2, time.second() * 6 ); 469 s2 = rotate( center, s2, time.second() * 6 );
463 p->setPen( QPen( color, 1 ) ); 470 p->setPen( QPen( color, 1 ) );
464 p->drawLine( s1, s2 ); 471 p->drawLine( s1, s2 );
465 472
466 if ( !clear ) 473 if ( !clear )
467 prevTime = currTime; 474 prevTime = currTime;
468} 475}
469 476
470void AnalogClock::display( const QTime& t ) 477void AnalogClock::display( const QTime& t )
471{ 478{
472 currTime = t; 479 currTime = t;
473 clear = true; 480 clear = true;
474 repaint( false ); 481 repaint( false );
475 clear = false; 482 clear = false;
476 repaint( false ); 483 repaint( false );
477} 484}
478 485
479QPoint AnalogClock::rotate( QPoint c, QPoint p, int a ) 486QPoint AnalogClock::rotate( QPoint c, QPoint p, int a )
480{ 487{
481 double angle = deg2rad * ( - a + 180 ); 488 double angle = deg2rad * ( - a + 180 );
482 double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) - 489 double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) -
483 ( p.y() - c.y() ) * sin( angle ); 490 ( p.y() - c.y() ) * sin( angle );
484 double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) + 491 double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) +
485 ( p.x() - c.x() ) * sin( angle ); 492 ( p.x() - c.x() ) * sin( angle );
486 return QPoint( nx, ny ); 493 return QPoint( nx, ny );
487} 494}
488void Clock::slotAdjustTime() 495
489{ 496void Clock::slotAdjustTime() {
490 QCopEnvelope e("QPE/System", "execute(QString)"); 497 QCopEnvelope e("QPE/System", "execute(QString)");
491 e << QString("systemtime"); 498 e << QString("systemtime");
492} 499}
diff --git a/noncore/tools/clock/clock.h b/noncore/tools/clock/clock.h
index 024dd28..be71b9d 100644
--- a/noncore/tools/clock/clock.h
+++ b/noncore/tools/clock/clock.h
@@ -1,99 +1,98 @@
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#ifndef CLOCK_H 20#ifndef CLOCK_H
21#define CLOCK_H 21#define CLOCK_H
22 22
23#include <qdatetime.h> 23#include <qdatetime.h>
24#include <qvbox.h> 24#include <qvbox.h>
25 25
26class QLCDNumber; 26class QLCDNumber;
27class QLabel; 27class QLabel;
28class QTimer; 28class QTimer;
29class QRadioButton; 29class QRadioButton;
30class QPushButton; 30class QPushButton;
31class QDateTime; 31class QDateTime;
32 32
33class AnalogClock : public QFrame 33class AnalogClock : public QFrame
34{ 34{
35 Q_OBJECT 35 Q_OBJECT
36 36
37public: 37public:
38 AnalogClock( QWidget * parent = 0, const char * name = 0 ) 38 AnalogClock( QWidget * parent = 0, const char * name = 0 )
39 : QFrame( parent, name ), clear(false) {} 39 : QFrame( parent, name ), clear(false) {}
40 40
41 QSizePolicy sizePolicy() const; 41 QSizePolicy sizePolicy() const;
42 42
43 void display( const QTime& time ); 43 void display( const QTime& time );
44 44
45protected: 45protected:
46 void drawContents( QPainter *p ); 46 void drawContents( QPainter *p );
47 47
48private: 48private:
49 QPoint rotate( QPoint center, QPoint p, int angle ); 49 QPoint rotate( QPoint center, QPoint p, int angle );
50 50
51 QTime currTime; 51 QTime currTime;
52 QTime prevTime; 52 QTime prevTime;
53 bool clear; 53 bool clear;
54}; 54};
55 55
56class Clock : public QVBox 56class Clock : public QVBox
57{ 57{
58 Q_OBJECT 58 Q_OBJECT
59 59
60public: 60public:
61 Clock( QWidget * parent = 0, const char * name = 0, WFlags f=0 ); 61 Clock( QWidget * parent = 0, const char * name = 0, WFlags f=0 );
62 ~Clock(); 62 ~Clock();
63 QDateTime when; 63 QDateTime when;
64 bool bSound; 64 bool bSound;
65 int hour, minute, snoozeTime; 65 int hour, minute, snoozeTime;
66private slots: 66private slots:
67 void slotSet(); 67 void slotSet();
68 void slotReset(); 68 void slotReset();
69 void modeSelect(int); 69 void modeSelect(int);
70 void updateClock(); 70 void updateClock();
71 void changeClock( bool ); 71 void changeClock( bool );
72 void slotSetAlarm(); 72 void slotSetAlarm();
73 void slotSnooze(); 73 void slotSnooze();
74 void slotToggleAlarm(); 74 void slotToggleAlarm();
75 void alarmOn(); 75 void alarmOn();
76 void alarmOff(); 76 void alarmOff();
77 void appMessage(const QCString& msg, const QByteArray& data); 77 void appMessage(const QCString& msg, const QByteArray& data);
78 void timerEvent( QTimerEvent *e ); 78 void timerEvent( QTimerEvent *e );
79 void slotAdjustTime(); 79 void slotAdjustTime();
80
81private: 80private:
82 void clearClock(); 81 void clearClock();
83 82
84 bool alarmBool; 83 bool alarmBool;
85 QTimer *t; 84 QTimer *t;
86 QLCDNumber *lcd; 85 QLCDNumber *lcd;
87 QLabel *date; 86 QLabel *date;
88 QLabel *ampmLabel; 87 QLabel *ampmLabel;
89 QPushButton *set, *reset, *alarmBtn, *snoozeBtn, *alarmOffBtn; 88 QPushButton *set, *reset, *alarmBtn, *snoozeBtn, *alarmOffBtn;
90 QRadioButton *clockRB, *swatchRB; 89 QRadioButton *clockRB, *swatchRB;
91 AnalogClock *aclock; 90 AnalogClock *aclock;
92 QTime swatch_start; 91 QTime swatch_start;
93 int swatch_totalms; 92 int swatch_totalms;
94 bool swatch_running; 93 bool swatch_running;
95 bool ampm; 94 bool ampm;
96}; 95};
97 96
98#endif 97#endif
99 98