-rw-r--r-- | noncore/tools/clock/clock.cpp | 11 | ||||
-rw-r--r-- | noncore/tools/clock/clock.h | 1 |
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,116 +1,118 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ +// changes added and Copyright (C) by L. J. Potter <ljp@llornkcor.com> 2002 #include "clock.h" #include "setAlarm.h" #include <qpe/qpeapplication.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/config.h> #include <qpe/timestring.h> #include <qpe/alarmserver.h> #include <qpe/sound.h> #include <qpe/resource.h> #include <qsound.h> #include <qtimer.h> #include <opie/oclickablelabel.h> #include <qlcdnumber.h> #include <qslider.h> #include <qlabel.h> #include <qlayout.h> #include <qtimer.h> #include <qpushbutton.h> #include <qradiobutton.h> #include <qbuttongroup.h> #include <qpainter.h> #include <qmessagebox.h> #include <qdatetime.h> #include <math.h> const double deg2rad = 0.017453292519943295769; // pi/180 const int sw_prec = 2; static void toggleScreenSaver( bool on ) { QCopEnvelope e("QPE/System", "setScreenSaverMode(int)" ); e << (on ? QPEApplication::Enable: QPEApplication::DisableSuspend ); } Clock::Clock( QWidget * parent, const char * name, WFlags f ) : QVBox( parent, name , f ) { setSpacing( 4 ); setMargin( 1 ); Config config( "qpe" ); config.setGroup("Time"); ampm = config.readBoolEntry( "AMPM", TRUE ); + snoozeBtn = new QPushButton ( this); snoozeBtn->setText( tr( "Snooze" ) ); aclock = new AnalogClock( this ); aclock->display( QTime::currentTime() ); aclock->setLineWidth( 2 ); QHBox *hb = new QHBox( this ); hb->setMargin( 0 ); QWidget *space = new QWidget( hb ); lcd = new QLCDNumber( hb ); lcd->setSegmentStyle( QLCDNumber::Flat ); lcd->setFrameStyle( QFrame::NoFrame ); lcd->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) ); lcd->setFixedHeight( 23 ); ampmLabel = new QLabel( tr("PM"), hb ); ampmLabel->setFont( QFont( "Helvetica", 14, QFont::Bold ) ); ampmLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred ) ); ampmLabel->setAlignment( AlignLeft | AlignBottom ); space = new QWidget( hb ); date = new QLabel( this ); date->setAlignment( AlignHCenter | AlignVCenter ); date->setFont( QFont( "Helvetica", 14, QFont::Bold ) ); date->setText( TimeString::longDateString( QDate::currentDate() ) ); QWidget *controls = new QWidget( this ); QGridLayout *gl = new QGridLayout( controls, 3, 2, 6, 4 ); QButtonGroup *grp = new QButtonGroup( controls ); grp->setRadioButtonExclusive( true ); grp->hide(); clockRB = new QRadioButton ( tr( "Clock" ), controls ); gl->addWidget( clockRB, 0, 0 ); grp->insert( clockRB ); swatchRB = new QRadioButton ( tr( "Stopwatch" ), controls ); gl->addWidget( swatchRB, 1, 0 ); grp->insert( swatchRB ); connect( grp, SIGNAL(clicked(int)), this, SLOT(modeSelect(int)) ); grp->setButton( 0 ); set = new QPushButton ( controls ); set->setMaximumSize(50,30); gl->addWidget( set, 0, 1 ); @@ -335,100 +337,105 @@ void Clock::slotToggleAlarm() config.writeEntry("clockAlarmSet","FALSE"); alarmOffBtn->setText( tr( "Alarm Is Off" ) ); snoozeBtn->hide(); alarmBool=FALSE; alarmOff(); } else { config.writeEntry("clockAlarmSet","TRUE"); alarmOffBtn->setText( tr( "Alarm Is On" ) ); snoozeBtn->show(); alarmBool=TRUE; alarmOn(); } config.write(); } void Clock::alarmOn() { QDate d = QDate::currentDate(); QTime tm((int)hour,(int)minute,0); qDebug("Time set "+tm.toString()); QTime t = QTime::currentTime(); if( t > tm) d = d.addDays(1); int warn = 0; QDateTime whenl(d,tm); when=whenl; AlarmServer::addAlarm( when, "QPE/Application/clock", "alarm(QDateTime,int)", warn ); setCaption("Alarm set: "+ whenl.toString()); } void Clock::alarmOff() { int warn = 0; bSound=FALSE; AlarmServer::deleteAlarm( when, "QPE/Application/clock", "alarm(QDateTime,int)", warn ); qDebug("Alarm Off "+ when.toString()); setCaption("Clock"); } void Clock::appMessage(const QCString& msg, const QByteArray& data) { int stopTimer = 0; int timerStay = 5000; bSound=TRUE; + qDebug("Message received in clock"); if ( msg == "alarm(QDateTime,int)" ) { Sound::soundAlarm(); stopTimer = startTimer( timerStay); } + show(); + raise(); + QPEApplication::setKeepRunning(); + setActiveWindow(); } void Clock::timerEvent( QTimerEvent *e ) { static int stop = 0; if ( stop < 120 && bSound) { Sound::soundAlarm(); stop++; } else { stop = 0; killTimer( e->timerId() ); alarmOffBtn->setText( tr( "Alarm Is Off" ) ); alarmBool=FALSE; snoozeBtn->hide(); setCaption("Clock: Alarm was missed."); } } QSizePolicy AnalogClock::sizePolicy() const { return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); } void AnalogClock::drawContents( QPainter *p ) { QRect r = contentsRect(); QPoint center( r.x() + r.width() / 2, r.y() + r.height() / 2 ); QPoint l1( r.x() + r.width() / 2, r.y() + 2 ); QPoint l2( r.x() + r.width() / 2, r.y() + 8 ); QPoint h1( r.x() + r.width() / 2, r.y() + r.height() / 4 ); QPoint h2( r.x() + r.width() / 2, r.y() + r.height() / 2 ); QPoint m1( r.x() + r.width() / 2, r.y() + r.height() / 8 ); QPoint m2( r.x() + r.width() / 2, r.y() + r.height() / 2 ); QPoint s1( r.x() + r.width() / 2, r.y() + 8 ); QPoint s2( r.x() + r.width() / 2, r.y() + r.height() / 2 ); QColor color( clear ? backgroundColor() : black ); QTime time = clear ? prevTime : currTime; if ( clear && prevTime.secsTo(currTime) > 1 ) { p->eraseRect( rect() ); return; } @@ -440,53 +447,53 @@ void AnalogClock::drawContents( QPainter *p ) p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) ); } if ( !clear || prevTime.minute() != currTime.minute() || prevTime.hour() != currTime.hour() ) { // draw hour pointer h1 = rotate( center, h1, 30 * ( time.hour() % 12 ) + time.minute() / 2 ); h2 = rotate( center, h2, 30 * ( time.hour() % 12 ) + time.minute() / 2 ); p->setPen( QPen( color, 3 ) ); p->drawLine( h1, h2 ); } if ( !clear || prevTime.minute() != currTime.minute() ) { // draw minute pointer m1 = rotate( center, m1, time.minute() * 6 ); m2 = rotate( center, m2, time.minute() * 6 ); p->setPen( QPen( color, 2 ) ); p->drawLine( m1, m2 ); } // draw second pointer s1 = rotate( center, s1, time.second() * 6 ); s2 = rotate( center, s2, time.second() * 6 ); p->setPen( QPen( color, 1 ) ); p->drawLine( s1, s2 ); if ( !clear ) prevTime = currTime; } void AnalogClock::display( const QTime& t ) { currTime = t; clear = true; repaint( false ); clear = false; repaint( false ); } QPoint AnalogClock::rotate( QPoint c, QPoint p, int a ) { double angle = deg2rad * ( - a + 180 ); double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) - ( p.y() - c.y() ) * sin( angle ); double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) + ( p.x() - c.x() ) * sin( angle ); return QPoint( nx, ny ); } -void Clock::slotAdjustTime() -{ + +void Clock::slotAdjustTime() { QCopEnvelope e("QPE/System", "execute(QString)"); e << QString("systemtime"); } 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 @@ -32,68 +32,67 @@ class QDateTime; class AnalogClock : public QFrame { Q_OBJECT public: AnalogClock( QWidget * parent = 0, const char * name = 0 ) : QFrame( parent, name ), clear(false) {} QSizePolicy sizePolicy() const; void display( const QTime& time ); protected: void drawContents( QPainter *p ); private: QPoint rotate( QPoint center, QPoint p, int angle ); QTime currTime; QTime prevTime; bool clear; }; class Clock : public QVBox { Q_OBJECT public: Clock( QWidget * parent = 0, const char * name = 0, WFlags f=0 ); ~Clock(); QDateTime when; bool bSound; int hour, minute, snoozeTime; private slots: void slotSet(); void slotReset(); void modeSelect(int); void updateClock(); void changeClock( bool ); void slotSetAlarm(); void slotSnooze(); void slotToggleAlarm(); void alarmOn(); void alarmOff(); void appMessage(const QCString& msg, const QByteArray& data); void timerEvent( QTimerEvent *e ); void slotAdjustTime(); - private: void clearClock(); bool alarmBool; QTimer *t; QLCDNumber *lcd; QLabel *date; QLabel *ampmLabel; QPushButton *set, *reset, *alarmBtn, *snoozeBtn, *alarmOffBtn; QRadioButton *clockRB, *swatchRB; AnalogClock *aclock; QTime swatch_start; int swatch_totalms; bool swatch_running; bool ampm; }; #endif |