summaryrefslogtreecommitdiff
Unidiff
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,43 +1,44 @@
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>
@@ -45,48 +46,49 @@
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 );
@@ -359,52 +361,57 @@ void Clock::alarmOn()
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
@@ -464,29 +471,29 @@ void AnalogClock::drawContents( QPainter *p )
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
@@ -56,44 +56,43 @@ private:
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