summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/tools/clock/clock.cpp25
1 files changed, 9 insertions, 16 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
@@ -8,40 +8,39 @@
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
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
36#include <qlcdnumber.h> 35#include <qlcdnumber.h>
37#include <qslider.h> 36#include <qslider.h>
38#include <qlabel.h> 37#include <qlabel.h>
39#include <qlayout.h> 38#include <qlayout.h>
40#include <qtimer.h> 39#include <qtimer.h>
41#include <qpushbutton.h> 40#include <qpushbutton.h>
42#include <qradiobutton.h> 41#include <qradiobutton.h>
43#include <qbuttongroup.h> 42#include <qbuttongroup.h>
44#include <qpainter.h> 43#include <qpainter.h>
45#include <qmessagebox.h> 44#include <qmessagebox.h>
46#include <qdatetime.h> 45#include <qdatetime.h>
47 46
@@ -85,25 +84,25 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
85 ampmLabel = new QLabel( tr("PM"), hb ); 84 ampmLabel = new QLabel( tr("PM"), hb );
86 ampmLabel->setFont( QFont( "Helvetica", 14, QFont::Bold ) ); 85 ampmLabel->setFont( QFont( "Helvetica", 14, QFont::Bold ) );
87 ampmLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred ) ); 86 ampmLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred ) );
88 ampmLabel->setAlignment( AlignLeft | AlignBottom ); 87 ampmLabel->setAlignment( AlignLeft | AlignBottom );
89 space = new QWidget( hb ); 88 space = new QWidget( hb );
90 89
91 date = new QLabel( this ); 90 date = new QLabel( this );
92 date->setAlignment( AlignHCenter | AlignVCenter ); 91 date->setAlignment( AlignHCenter | AlignVCenter );
93 date->setFont( QFont( "Helvetica", 14, QFont::Bold ) ); 92 date->setFont( QFont( "Helvetica", 14, QFont::Bold ) );
94 date->setText( TimeString::longDateString( QDate::currentDate() ) ); 93 date->setText( TimeString::longDateString( QDate::currentDate() ) );
95 94
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
99 QButtonGroup *grp = new QButtonGroup( controls ); 98 QButtonGroup *grp = new QButtonGroup( controls );
100 grp->setRadioButtonExclusive( true ); 99 grp->setRadioButtonExclusive( true );
101 grp->hide(); 100 grp->hide();
102 101
103 clockRB = new QRadioButton ( tr( "Clock" ), controls ); 102 clockRB = new QRadioButton ( tr( "Clock" ), controls );
104 gl->addWidget( clockRB, 0, 0 ); 103 gl->addWidget( clockRB, 0, 0 );
105 grp->insert( clockRB ); 104 grp->insert( clockRB );
106 105
107 swatchRB = new QRadioButton ( tr( "Stopwatch" ), controls ); 106 swatchRB = new QRadioButton ( tr( "Stopwatch" ), controls );
108 gl->addWidget( swatchRB, 1, 0 ); 107 gl->addWidget( swatchRB, 1, 0 );
109 grp->insert( swatchRB ); 108 grp->insert( swatchRB );
@@ -124,29 +123,24 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
124 reset->setEnabled( FALSE ); 123 reset->setEnabled( FALSE );
125 grp->insert( reset ); 124 grp->insert( reset );
126 125
127 alarmOffBtn = new QPushButton ( controls ); 126 alarmOffBtn = new QPushButton ( controls );
128// alarmOffBtn->setMaximumSize(60,30); 127// alarmOffBtn->setMaximumSize(60,30);
129 gl->addWidget( alarmOffBtn, 0, 2 ); 128 gl->addWidget( alarmOffBtn, 0, 2 );
130 129
131 alarmBtn = new QPushButton ( controls ); 130 alarmBtn = new QPushButton ( controls );
132 // alarmBtn->setMaximumSize(60,30); 131 // alarmBtn->setMaximumSize(60,30);
133 gl->addWidget( alarmBtn, 1, 2 ); 132 gl->addWidget( alarmBtn, 1, 2 );
134 alarmBtn->setText( tr( "Set Alarm" ) ); 133 alarmBtn->setText( tr( "Set Alarm" ) );
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() ) );
142 connect( reset, SIGNAL( clicked() ), SLOT( slotReset() ) ); 136 connect( reset, SIGNAL( clicked() ), SLOT( slotReset() ) );
143 137
144 connect( alarmBtn, SIGNAL( clicked() ), SLOT( slotSetAlarm() ) ); 138 connect( alarmBtn, SIGNAL( clicked() ), SLOT( slotSetAlarm() ) );
145 connect( snoozeBtn, SIGNAL( clicked() ), SLOT( slotSnooze() ) ); 139 connect( snoozeBtn, SIGNAL( clicked() ), SLOT( slotSnooze() ) );
146 connect( alarmOffBtn, SIGNAL( clicked() ), SLOT( slotToggleAlarm() ) ); 140 connect( alarmOffBtn, SIGNAL( clicked() ), SLOT( slotToggleAlarm() ) );
147 141
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
151 t = new QTimer( this ); 145 t = new QTimer( this );
152 connect( t, SIGNAL( timeout() ), SLOT( updateClock() ) ); 146 connect( t, SIGNAL( timeout() ), SLOT( updateClock() ) );
@@ -352,58 +346,62 @@ void Clock::alarmOn()
352 QDate d = QDate::currentDate(); 346 QDate d = QDate::currentDate();
353 QTime tm((int)hour,(int)minute,0); 347 QTime tm((int)hour,(int)minute,0);
354 qDebug("Time set "+tm.toString()); 348 qDebug("Time set "+tm.toString());
355 QTime t = QTime::currentTime(); 349 QTime t = QTime::currentTime();
356 if( t > tm) 350 if( t > tm)
357 d = d.addDays(1); 351 d = d.addDays(1);
358 int warn; 352 int warn;
359 QDateTime whenl(d,tm); 353 QDateTime whenl(d,tm);
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}
366 360
367void Clock::alarmOff() 361void Clock::alarmOff()
368{ 362{
369 int warn; 363 int warn;
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}
377 371
378void Clock::appMessage(const QCString& msg, const QByteArray& data) 372void Clock::appMessage(const QCString& msg, const QByteArray& data)
379{ 373{
380 int stopTimer = 0; 374 int stopTimer = 0;
381 int timerStay = 5000; 375 int timerStay = 5000;
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}
388 382
389void Clock::timerEvent( QTimerEvent *e ) 383void Clock::timerEvent( QTimerEvent *e )
390{ 384{
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();
394 stop++; 388 stop++;
395 } else { 389 } else {
396 stop = 0; 390 stop = 0;
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 }
399} 397}
400 398
401 399
402QSizePolicy AnalogClock::sizePolicy() const 400QSizePolicy AnalogClock::sizePolicy() const
403{ 401{
404 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); 402 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
405} 403}
406 404
407void AnalogClock::drawContents( QPainter *p ) 405void AnalogClock::drawContents( QPainter *p )
408{ 406{
409 QRect r = contentsRect(); 407 QRect r = contentsRect();
@@ -472,17 +470,12 @@ void AnalogClock::display( const QTime& t )
472 repaint( false ); 470 repaint( false );
473} 471}
474 472
475QPoint AnalogClock::rotate( QPoint c, QPoint p, int a ) 473QPoint AnalogClock::rotate( QPoint c, QPoint p, int a )
476{ 474{
477 double angle = deg2rad * ( - a + 180 ); 475 double angle = deg2rad * ( - a + 180 );
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}