summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/clock/clock.cpp313
-rw-r--r--noncore/tools/clock/clock.h17
-rw-r--r--noncore/tools/clock/clock.pro18
-rw-r--r--noncore/tools/clock/setAlarm.cpp183
-rw-r--r--noncore/tools/clock/setAlarm.h57
5 files changed, 498 insertions, 90 deletions
diff --git a/noncore/tools/clock/clock.cpp b/noncore/tools/clock/clock.cpp
index ef93e11..d5d77bc 100644
--- a/noncore/tools/clock/clock.cpp
+++ b/noncore/tools/clock/clock.cpp
@@ -19,13 +19,20 @@
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "clock.h" 21#include "clock.h"
22#include "setAlarm.h"
22 23
23#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
24#include <qpe/qcopenvelope_qws.h> 25#include <qpe/qcopenvelope_qws.h>
25#include <qpe/config.h> 26#include <qpe/config.h>
26#include <qpe/timestring.h> 27#include <qpe/timestring.h>
28#include <qpe/alarmserver.h>
29#include <qpe/sound.h>
30#include <qpe/resource.h>
31#include <qsound.h>
32#include <qtimer.h>
27 33
28#include <qlcdnumber.h> 34#include <qlcdnumber.h>
35#include <qslider.h>
29#include <qlabel.h> 36#include <qlabel.h>
30#include <qlayout.h> 37#include <qlayout.h>
31#include <qtimer.h> 38#include <qtimer.h>
@@ -33,10 +40,12 @@
33#include <qradiobutton.h> 40#include <qradiobutton.h>
34#include <qbuttongroup.h> 41#include <qbuttongroup.h>
35#include <qpainter.h> 42#include <qpainter.h>
43#include <qmessagebox.h>
44#include <qdatetime.h>
36 45
37#include <math.h> 46#include <math.h>
38 47
39 const double deg2rad = 0.017453292519943295769;// pi/180 48const double deg2rad = 0.017453292519943295769; // pi/180
40const int sw_prec = 2; 49const int sw_prec = 2;
41 50
42static void toggleScreenSaver( bool on ) 51static void toggleScreenSaver( bool on )
@@ -55,6 +64,9 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
55 config.setGroup("Time"); 64 config.setGroup("Time");
56 ampm = config.readBoolEntry( "AMPM", TRUE ); 65 ampm = config.readBoolEntry( "AMPM", TRUE );
57 66
67 snoozeBtn = new QPushButton ( this);
68 snoozeBtn->setText( tr( "Snooze" ) );
69
58 aclock = new AnalogClock( this ); 70 aclock = new AnalogClock( this );
59 aclock->display( QTime::currentTime() ); 71 aclock->display( QTime::currentTime() );
60 aclock->setLineWidth( 2 ); 72 aclock->setLineWidth( 2 );
@@ -98,6 +110,7 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
98 grp->setButton( 0 ); 110 grp->setButton( 0 );
99 111
100 set = new QPushButton ( controls ); 112 set = new QPushButton ( controls );
113 set->setMaximumSize(50,30);
101 gl->addWidget( set, 0, 1 ); 114 gl->addWidget( set, 0, 1 );
102 set->setText( tr( "Start" ) ); 115 set->setText( tr( "Start" ) );
103 set->setEnabled( FALSE ); 116 set->setEnabled( FALSE );
@@ -109,9 +122,25 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
109 reset->setEnabled( FALSE ); 122 reset->setEnabled( FALSE );
110 grp->insert( reset ); 123 grp->insert( reset );
111 124
125 alarmOffBtn = new QPushButton ( controls );
126 alarmOffBtn->setMaximumSize(60,30);
127 gl->addWidget( alarmOffBtn, 0, 2 );
128
129 alarmBtn = new QPushButton ( controls );
130 alarmBtn->setMaximumSize(60,30);
131 gl->addWidget( alarmBtn, 1, 2 );
132 alarmBtn->setText( tr( "Set Alarm" ) );
133
112 connect( set, SIGNAL( pressed() ), SLOT( slotSet() ) ); 134 connect( set, SIGNAL( pressed() ), SLOT( slotSet() ) );
113 connect( reset, SIGNAL( clicked() ), SLOT( slotReset() ) ); 135 connect( reset, SIGNAL( clicked() ), SLOT( slotReset() ) );
114 136
137 connect( alarmBtn, SIGNAL( clicked() ), SLOT( slotSetAlarm() ) );
138 connect( snoozeBtn, SIGNAL( clicked() ), SLOT( slotSnooze() ) );
139 connect( alarmOffBtn, SIGNAL( clicked() ), SLOT( slotToggleAlarm() ) );
140
141 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)),
142 this, SLOT(appMessage(const QCString&, const QByteArray&)) );
143
115 t = new QTimer( this ); 144 t = new QTimer( this );
116 connect( t, SIGNAL( timeout() ), SLOT( updateClock() ) ); 145 connect( t, SIGNAL( timeout() ), SLOT( updateClock() ) );
117 t->start( 1000 ); 146 t->start( 1000 );
@@ -123,6 +152,22 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
123 152
124 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) ); 153 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) );
125 154
155 QString tmp = config.readEntry("clockAlarmHour", "");
156 bool ok;
157 hour = tmp.toInt(&ok,10);
158 tmp = config.readEntry("clockAlarmMinute","");
159 minute = tmp.toInt(&ok,10);
160
161 if( config.readEntry("clockAlarmSet","FALSE") == "TRUE") {
162 alarmOffBtn->setText( tr( "Alarm On" ) );
163 alarmBool=TRUE;
164 snoozeBtn->show();
165 } else {
166 alarmOffBtn->setText( tr( "Alarm Off" ) );
167 alarmBool=FALSE;
168 snoozeBtn->hide();
169 }
170
126 QTimer::singleShot( 0, this, SLOT(updateClock()) ); 171 QTimer::singleShot( 0, this, SLOT(updateClock()) );
127 modeSelect(0); 172 modeSelect(0);
128} 173}
@@ -135,39 +180,39 @@ Clock::~Clock()
135void Clock::updateClock() 180void Clock::updateClock()
136{ 181{
137 if ( clockRB->isChecked() ) { 182 if ( clockRB->isChecked() ) {
138 QTime tm = QDateTime::currentDateTime().time(); 183 QTime tm = QDateTime::currentDateTime().time();
139 QString s; 184 QString s;
140 if ( ampm ) { 185 if ( ampm ) {
141 int hour = tm.hour(); 186 int hour = tm.hour();
142 if (hour == 0) 187 if (hour == 0)
143 hour = 12; 188 hour = 12;
144 if (hour > 12) 189 if (hour > 12)
145 hour -= 12; 190 hour -= 12;
146 s.sprintf( "%2d%c%02d", hour, ':', tm.minute() ); 191 s.sprintf( "%2d%c%02d", hour, ':', tm.minute() );
147 ampmLabel->setText( (tm.hour() >= 12) ? "PM" : "AM" ); 192 ampmLabel->setText( (tm.hour() >= 12) ? "PM" : "AM" );
148 ampmLabel->show(); 193 ampmLabel->show();
149 } else { 194 } else {
150 s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() ); 195 s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() );
151 ampmLabel->hide(); 196 ampmLabel->hide();
152 } 197 }
153 lcd->display( s ); 198 lcd->display( s );
154 lcd->repaint( FALSE ); 199 lcd->repaint( FALSE );
155 aclock->display( QTime::currentTime() ); 200 aclock->display( QTime::currentTime() );
156 date->setText( TimeString::longDateString( QDate::currentDate() ) ); 201 date->setText( TimeString::longDateString( QDate::currentDate() ) );
157 } else { 202 } else {
158 QTime swatch_time; 203 QTime swatch_time;
159 QString lcdtext; 204 QString lcdtext;
160 int totalms = swatch_totalms; 205 int totalms = swatch_totalms;
161 if ( swatch_running ) 206 if ( swatch_running )
162 totalms += swatch_start.elapsed(); 207 totalms += swatch_start.elapsed();
163 swatch_time = QTime(0,0,0).addMSecs(totalms); 208 swatch_time = QTime(0,0,0).addMSecs(totalms);
164 QString d = swatch_running ? QString(" ") 209 QString d = swatch_running ? QString(" ")
165 : QString::number(totalms%1000+1000); 210 : QString::number(totalms%1000+1000);
166 lcdtext = swatch_time.toString() + "." + d.right(3).left(sw_prec); 211 lcdtext = swatch_time.toString() + "." + d.right(3).left(sw_prec);
167 lcd->display( lcdtext ); 212 lcd->display( lcdtext );
168 lcd->repaint( FALSE ); 213 lcd->repaint( FALSE );
169 aclock->display( swatch_time ); 214 aclock->display( swatch_time );
170 date->setText( TimeString::longDateString( QDate::currentDate() ) ); 215 date->setText( TimeString::longDateString( QDate::currentDate() ) );
171 } 216 }
172} 217}
173 218
@@ -186,19 +231,19 @@ void Clock::clearClock( void )
186void Clock::slotSet() 231void Clock::slotSet()
187{ 232{
188 if ( t->isActive() ) { 233 if ( t->isActive() ) {
189 swatch_totalms += swatch_start.elapsed(); 234 swatch_totalms += swatch_start.elapsed();
190 set->setText( tr( "Start" ) ); 235 set->setText( tr( "Start" ) );
191 t->stop(); 236 t->stop();
192 swatch_running = FALSE; 237 swatch_running = FALSE;
193 toggleScreenSaver( TRUE ); 238 toggleScreenSaver( TRUE );
194 updateClock(); 239 updateClock();
195 } else { 240 } else {
196 swatch_start.start(); 241 swatch_start.start();
197 set->setText( tr( "Stop" ) ); 242 set->setText( tr( "Stop" ) );
198 t->start( 1000 ); 243 t->start( 1000 );
199 swatch_running = TRUE; 244 swatch_running = TRUE;
200 // disable screensaver while stop watch is running 245 // disable screensaver while stop watch is running
201 toggleScreenSaver( FALSE ); 246 toggleScreenSaver( FALSE );
202 } 247 }
203} 248}
204 249
@@ -209,7 +254,7 @@ void Clock::slotReset()
209 swatch_totalms = 0; 254 swatch_totalms = 0;
210 255
211 if (swatch_running ) 256 if (swatch_running )
212 t->start(1000); 257 t->start(1000);
213 258
214 updateClock(); 259 updateClock();
215} 260}
@@ -217,24 +262,136 @@ void Clock::slotReset()
217void Clock::modeSelect( int m ) 262void Clock::modeSelect( int m )
218{ 263{
219 if ( m ) { 264 if ( m ) {
220 lcd->setNumDigits( 8+1+sw_prec ); 265 lcd->setNumDigits( 8+1+sw_prec );
221 lcd->setMinimumWidth( lcd->sizeHint().width() ); 266 lcd->setMinimumWidth( lcd->sizeHint().width() );
222 set->setEnabled( TRUE ); 267 set->setEnabled( TRUE );
223 reset->setEnabled( TRUE ); 268 reset->setEnabled( TRUE );
224 ampmLabel->hide(); 269 ampmLabel->hide();
225 270
226 if ( !swatch_running ) 271 if ( !swatch_running )
227 t->stop(); 272 t->stop();
228 } else { 273 } else {
229 lcd->setNumDigits( 5 ); 274 lcd->setNumDigits( 5 );
230 lcd->setMinimumWidth( lcd->sizeHint().width() ); 275 lcd->setMinimumWidth( lcd->sizeHint().width() );
231 set->setEnabled( FALSE ); 276 set->setEnabled( FALSE );
232 reset->setEnabled( FALSE ); 277 reset->setEnabled( FALSE );
233 t->start(1000); 278 t->start(1000);
234 } 279 }
235 updateClock(); 280 updateClock();
236} 281}
237 282
283//this sets the alarm time
284void Clock::slotSetAlarm()
285{
286 if( !snoozeBtn->isHidden())
287 slotToggleAlarm();
288 Set_Alarm *setAlarmDlg;
289 setAlarmDlg = new Set_Alarm(this,"SetAlarm", TRUE);
290 int result = setAlarmDlg->exec();
291 if(result == 1) {
292 Config config( "qpe" );
293 config.setGroup("Time");
294 QString tmp;
295 hour = setAlarmDlg->Hour_Slider->value();
296 minute = setAlarmDlg->Minute_Slider->value();
297 snoozeTime=setAlarmDlg->SnoozeSlider->value();
298 if(ampm) {
299 if(setAlarmDlg->Pm_RadioButton->isChecked() && hour < 12 )
300 hour+=12;
301 }
302 config.writeEntry("clockAlarmHour", tmp.setNum( hour ),10);
303 config.writeEntry("clockAlarmMinute",tmp.setNum( minute ),10);
304 config.writeEntry("clockAlarmSnooze",tmp.setNum( snoozeTime ),10);
305 config.write();
306 }
307}
308
309void Clock::slotSnooze()
310{
311 bSound=FALSE;
312 int warn;
313 QTime t = QTime::currentTime();
314 QDateTime whenl( when.date(), t.addSecs( snoozeTime*60));
315 when=whenl;
316 AlarmServer::addAlarm( when,
317 "QPE/Application/clock",
318 "alarm(QDateTime,int)", warn );
319
320}
321
322//toggles alarm on/off
323void Clock::slotToggleAlarm()
324{
325 Config config( "qpe" );
326 config.setGroup("Time");
327 if(alarmBool) {
328 config.writeEntry("clockAlarmSet","FALSE");
329 alarmOffBtn->setText( tr( "Alarm Off" ) );
330 snoozeBtn->hide();
331 alarmBool=FALSE;
332 alarmOff();
333 } else {
334 config.writeEntry("clockAlarmSet","TRUE");
335 alarmOffBtn->setText( tr( "Alarm On" ) );
336 snoozeBtn->show();
337 alarmBool=TRUE;
338 alarmOn();
339 }
340 config.write();
341}
342
343void Clock::alarmOn()
344{
345 QDate d = QDate::currentDate();
346 QTime tm((int)hour,(int)minute,0);
347 qDebug("Time set "+tm.toString());
348 QTime t = QTime::currentTime();
349 if( t > tm)
350 d = d.addDays(1);
351 int warn;
352 QDateTime whenl(d,tm);
353 when=whenl;
354 AlarmServer::addAlarm( when,
355 "QPE/Application/clock",
356 "alarm(QDateTime,int)", warn );
357 QMessageBox::message("Note","Alarm is set for:\n"+ whenl.toString());
358}
359
360void Clock::alarmOff()
361{
362 int warn;
363 bSound=FALSE;
364 AlarmServer::deleteAlarm( when,
365 "QPE/Application/clock",
366 "alarm(QDateTime,int)", warn );
367 qDebug("Alarm Off "+ when.toString());
368
369}
370
371void Clock::appMessage(const QCString& msg, const QByteArray& data)
372{
373 int stopTimer = 0;
374 int timerStay = 5000;
375 bSound=TRUE;
376 if ( msg == "alarm(QDateTime,int)" ) {
377 Sound::soundAlarm();
378 stopTimer = startTimer( timerStay);
379 }
380}
381
382void Clock::timerEvent( QTimerEvent *e )
383{
384 static int stop = 0;
385 if ( stop < 10 && bSound) {
386 Sound::soundAlarm();
387 stop++;
388 } else {
389 stop = 0;
390 killTimer( e->timerId() );
391 }
392}
393
394
238QSizePolicy AnalogClock::sizePolicy() const 395QSizePolicy AnalogClock::sizePolicy() const
239{ 396{
240 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); 397 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
@@ -261,32 +418,32 @@ void AnalogClock::drawContents( QPainter *p )
261 QTime time = clear ? prevTime : currTime; 418 QTime time = clear ? prevTime : currTime;
262 419
263 if ( clear && prevTime.secsTo(currTime) > 1 ) { 420 if ( clear && prevTime.secsTo(currTime) > 1 ) {
264 p->eraseRect( rect() ); 421 p->eraseRect( rect() );
265 return; 422 return;
266 } 423 }
267 424
268 if ( !clear ) { 425 if ( !clear ) {
269 // draw ticks 426 // draw ticks
270 p->setPen( QPen( color, 1 ) ); 427 p->setPen( QPen( color, 1 ) );
271 for ( int i = 0; i < 12; i++ ) 428 for ( int i = 0; i < 12; i++ )
272 p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) ); 429 p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) );
273 } 430 }
274 431
275 if ( !clear || prevTime.minute() != currTime.minute() || 432 if ( !clear || prevTime.minute() != currTime.minute() ||
276 prevTime.hour() != currTime.hour() ) { 433 prevTime.hour() != currTime.hour() ) {
277 // draw hour pointer 434 // draw hour pointer
278 h1 = rotate( center, h1, 30 * ( time.hour() % 12 ) + time.minute() / 2 ); 435 h1 = rotate( center, h1, 30 * ( time.hour() % 12 ) + time.minute() / 2 );
279 h2 = rotate( center, h2, 30 * ( time.hour() % 12 ) + time.minute() / 2 ); 436 h2 = rotate( center, h2, 30 * ( time.hour() % 12 ) + time.minute() / 2 );
280 p->setPen( QPen( color, 3 ) ); 437 p->setPen( QPen( color, 3 ) );
281 p->drawLine( h1, h2 ); 438 p->drawLine( h1, h2 );
282 } 439 }
283 440
284 if ( !clear || prevTime.minute() != currTime.minute() ) { 441 if ( !clear || prevTime.minute() != currTime.minute() ) {
285 // draw minute pointer 442 // draw minute pointer
286 m1 = rotate( center, m1, time.minute() * 6 ); 443 m1 = rotate( center, m1, time.minute() * 6 );
287 m2 = rotate( center, m2, time.minute() * 6 ); 444 m2 = rotate( center, m2, time.minute() * 6 );
288 p->setPen( QPen( color, 2 ) ); 445 p->setPen( QPen( color, 2 ) );
289 p->drawLine( m1, m2 ); 446 p->drawLine( m1, m2 );
290 } 447 }
291 448
292 // draw second pointer 449 // draw second pointer
@@ -296,7 +453,7 @@ void AnalogClock::drawContents( QPainter *p )
296 p->drawLine( s1, s2 ); 453 p->drawLine( s1, s2 );
297 454
298 if ( !clear ) 455 if ( !clear )
299 prevTime = currTime; 456 prevTime = currTime;
300} 457}
301 458
302void AnalogClock::display( const QTime& t ) 459void AnalogClock::display( const QTime& t )
@@ -312,8 +469,8 @@ QPoint AnalogClock::rotate( QPoint c, QPoint p, int a )
312{ 469{
313 double angle = deg2rad * ( - a + 180 ); 470 double angle = deg2rad * ( - a + 180 );
314 double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) - 471 double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) -
315 ( p.y() - c.y() ) * sin( angle ); 472 ( p.y() - c.y() ) * sin( angle );
316 double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) + 473 double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) +
317 ( p.x() - c.x() ) * sin( angle ); 474 ( p.x() - c.x() ) * sin( angle );
318 return QPoint( nx, ny ); 475 return QPoint( nx, ny );
319} 476}
diff --git a/noncore/tools/clock/clock.h b/noncore/tools/clock/clock.h
index 6dbebf7..9b756b5 100644
--- a/noncore/tools/clock/clock.h
+++ b/noncore/tools/clock/clock.h
@@ -28,6 +28,7 @@ class QLabel;
28class QTimer; 28class QTimer;
29class QRadioButton; 29class QRadioButton;
30class QPushButton; 30class QPushButton;
31class QDateTime;
31 32
32class AnalogClock : public QFrame 33class AnalogClock : public QFrame
33{ 34{
@@ -35,7 +36,7 @@ class AnalogClock : public QFrame
35 36
36public: 37public:
37 AnalogClock( QWidget * parent = 0, const char * name = 0 ) 38 AnalogClock( QWidget * parent = 0, const char * name = 0 )
38 : QFrame( parent, name ), clear(false) {} 39 : QFrame( parent, name ), clear(false) {}
39 40
40 QSizePolicy sizePolicy() const; 41 QSizePolicy sizePolicy() const;
41 42
@@ -59,22 +60,32 @@ class Clock : public QVBox
59public: 60public:
60 Clock( QWidget * parent = 0, const char * name = 0, WFlags f=0 ); 61 Clock( QWidget * parent = 0, const char * name = 0, WFlags f=0 );
61 ~Clock(); 62 ~Clock();
62 63 QDateTime when;
64 bool bSound;
65 int hour, minute, snoozeTime;
63private slots: 66private slots:
64 void slotSet(); 67 void slotSet();
65 void slotReset(); 68 void slotReset();
66 void modeSelect(int); 69 void modeSelect(int);
67 void updateClock(); 70 void updateClock();
68 void changeClock( bool ); 71 void changeClock( bool );
72 void slotSetAlarm();
73 void slotSnooze();
74 void slotToggleAlarm();
75 void alarmOn();
76 void alarmOff();
77 void appMessage(const QCString& msg, const QByteArray& data);
78 void timerEvent( QTimerEvent *e );
69 79
70private: 80private:
71 void clearClock(); 81 void clearClock();
72 82
83 bool alarmBool;
73 QTimer *t; 84 QTimer *t;
74 QLCDNumber *lcd; 85 QLCDNumber *lcd;
75 QLabel *date; 86 QLabel *date;
76 QLabel *ampmLabel; 87 QLabel *ampmLabel;
77 QPushButton *set, *reset; 88 QPushButton *set, *reset, *alarmBtn, *snoozeBtn, *alarmOffBtn;
78 QRadioButton *clockRB, *swatchRB; 89 QRadioButton *clockRB, *swatchRB;
79 AnalogClock *aclock; 90 AnalogClock *aclock;
80 QTime swatch_start; 91 QTime swatch_start;
diff --git a/noncore/tools/clock/clock.pro b/noncore/tools/clock/clock.pro
index ec27adc..10d375f 100644
--- a/noncore/tools/clock/clock.pro
+++ b/noncore/tools/clock/clock.pro
@@ -1,13 +1,13 @@
1 TEMPLATE= app 1TEMPLATE = app
2 CONFIG = qt warn_on release 2CONFIG = qt warn_on release
3 DESTDIR = $(OPIEDIR)/bin 3DESTDIR = $(OPIEDIR)/bin
4 HEADERS = clock.h 4HEADERS = clock.h setAlarm.h
5 SOURCES = clock.cpp \ 5SOURCES = clock.cpp setAlarm.cpp \
6 main.cpp 6 main.cpp
7INCLUDEPATH += $(OPIEDIR)/include 7INCLUDEPATH += $(OPIEDIR)/include
8 DEPENDPATH+= $(OPIEDIR)/include 8DEPENDPATH += $(OPIEDIR)/include
9LIBS += -lqpe 9LIBS += -lqpe
10 INTERFACES= 10INTERFACES =
11 TARGET = clock 11TARGET = clock
12 12
13TRANSLATIONS = ../i18n/de/clock.ts 13TRANSLATIONS = ../i18n/de/clock.ts
diff --git a/noncore/tools/clock/setAlarm.cpp b/noncore/tools/clock/setAlarm.cpp
new file mode 100644
index 0000000..01e52f6
--- a/dev/null
+++ b/noncore/tools/clock/setAlarm.cpp
@@ -0,0 +1,183 @@
1 /***************************************************************************
2// setAlarm.cpp - description
3// -------------------
4// Created: Wed Mar 13 19:47:24 2002
5// copyright : (C) 2002 by ljp
6// email : ljp@llornkcor.com
7//
8***************************************************************************
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 ***************************************************************************/
14
15#include "setAlarm.h"
16
17#include <qpe/config.h>
18
19#include <qpe/qpeapplication.h>
20#include <qstring.h>
21#include <qlabel.h>
22#include <qlcdnumber.h>
23#include <qpushbutton.h>
24#include <qradiobutton.h>
25#include <qslider.h>
26#include <qlayout.h>
27#include <qvariant.h>
28#include <qtooltip.h>
29#include <qwhatsthis.h>
30#include <qbuttongroup.h>
31
32Set_Alarm::Set_Alarm( QWidget* parent, const char* name, bool modal, WFlags fl )
33 : QDialog( parent, name, modal, fl )
34{
35 if ( !name )
36 setName( "Set_Alarm" );
37 resize( 240, 101 );
38 setMaximumSize( QSize( 240, 320 ) );
39 setCaption( tr( "Set Alarm" ) );
40 connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) );
41
42 Set_AlarmLayout = new QGridLayout( this );
43 Set_AlarmLayout->setSpacing( 6 );
44 Set_AlarmLayout->setMargin( 11 );
45
46 TextLabel1 = new QLabel( this, "TextLabel1" );
47 TextLabel1->setText( tr( "Hour" ) );
48
49 Set_AlarmLayout->addWidget( TextLabel1, 0, 0 );
50
51 TextLabel2 = new QLabel( this, "TextLabel2" );
52 TextLabel2->setText( tr( "Minute" ) );
53
54 Set_AlarmLayout->addMultiCellWidget( TextLabel2, 0, 0, 1, 2 );
55
56 Hour_Slider = new QSlider( this, "Hour_Slider" );
57 Hour_Slider->setPageStep( 1);
58 Hour_Slider->setOrientation( QSlider::Horizontal );
59 connect(Hour_Slider, SIGNAL( valueChanged(int)),this,SLOT(slotChangeHour(int)));
60
61 Set_AlarmLayout->addWidget( Hour_Slider, 2, 0 );
62
63 Hour_LCDNumber = new QLCDNumber( this, "Hour_LCDNumber" );
64 Hour_LCDNumber->setFrameShape( QLCDNumber::Box );
65 Hour_LCDNumber->setFrameShadow( QLCDNumber::Plain );
66 Hour_LCDNumber->setSegmentStyle( QLCDNumber::Flat );
67
68 Set_AlarmLayout->addWidget( Hour_LCDNumber, 1, 0 );
69
70 Minute_Slider = new QSlider( this, "Minute_Slider" );
71 Minute_Slider->setMaxValue( 59);
72 Minute_Slider->setOrientation( QSlider::Horizontal );
73 connect(Minute_Slider, SIGNAL( valueChanged(int)),this,SLOT(slotChangeMinute(int)));
74
75 Set_AlarmLayout->addMultiCellWidget( Minute_Slider, 2, 2, 1, 2 );
76
77 Minute_LCDNumber = new QLCDNumber( this, "Minute_LCDNumber" );
78 Minute_LCDNumber->setFrameShape( QLCDNumber::Box );
79 Minute_LCDNumber->setFrameShadow( QLCDNumber::Plain );
80 Minute_LCDNumber->setSegmentStyle( QLCDNumber::Flat );
81
82 Set_AlarmLayout->addMultiCellWidget( Minute_LCDNumber, 1, 1, 1, 2 );
83
84 Am_RadioButton = new QRadioButton( this, "Am_RadioButton" );
85 Am_RadioButton->setText( tr( "AM" ) );
86 Am_RadioButton->setChecked(TRUE);
87 connect( Am_RadioButton, SIGNAL(toggled(bool)),this,SLOT( amButtonToggled(bool)));
88
89 Set_AlarmLayout->addMultiCellWidget( Am_RadioButton, 0, 1, 3, 4 );
90
91
92 Pm_RadioButton = new QRadioButton( this, "Pm_RadioButton" );
93 Pm_RadioButton->setText( tr( "PM" ) );
94 connect( Pm_RadioButton, SIGNAL(toggled(bool)),this,SLOT( pmButtonToggled(bool)));
95
96 Set_AlarmLayout->addMultiCellWidget(Pm_RadioButton, 1, 2, 3, 4 );
97
98 TextLabel3 = new QLabel( this, "TextLabel3" );
99 TextLabel3->setText( tr( "Snooze Delay\n(minutes)" ) );
100
101 Set_AlarmLayout->addMultiCellWidget( TextLabel3, 3, 3, 0, 1 );
102
103 Snooze_LCDNumber = new QLCDNumber( this, "Snooze_LCDNumber" );
104 Snooze_LCDNumber->setFrameShape( QLCDNumber::Box );
105 Snooze_LCDNumber->setFrameShadow( QLCDNumber::Plain );
106 Snooze_LCDNumber->setSegmentStyle( QLCDNumber::Flat );
107
108 Set_AlarmLayout->addMultiCellWidget( Snooze_LCDNumber, 3, 3, 1, 2 );
109
110 SnoozeSlider = new QSlider( this, "SnoozeSlider" );
111 SnoozeSlider->setMaxValue( 60 );
112 SnoozeSlider->setOrientation( QSlider::Horizontal );
113 connect(SnoozeSlider, SIGNAL( valueChanged(int)),this,SLOT(slotChangeSnooze(int)));
114
115 Set_AlarmLayout->addMultiCellWidget( SnoozeSlider, 3, 3, 3, 4 );
116
117 Config config( "qpe" );
118 config.setGroup("Time");
119
120 bool ok;
121 bool ampm = config.readBoolEntry( "AMPM", TRUE );
122 QString alarmHour=config.readEntry("clockAlarmHour","8");
123 int i_alarmHour = alarmHour.toInt(&ok,10);
124 QString alarmMinute=config.readEntry("clockAlarmMinute","0");
125 QString snoozeTime=config.readEntry("clockAlarmSnooze","0");
126 if(ampm) {
127 Hour_Slider->setMaxValue( 12);
128 Hour_Slider->setMinValue( 1);
129
130 if( i_alarmHour > 12) {
131 i_alarmHour = i_alarmHour - 12;
132 Pm_RadioButton->setChecked(TRUE);
133 }
134 Hour_Slider->setValue( i_alarmHour);
135 Minute_Slider->setValue( alarmMinute.toInt(&ok,10) );
136 SnoozeSlider->setValue( snoozeTime.toInt(&ok,10) );
137 } else {
138 Hour_Slider->setMaxValue( 23);
139 Hour_Slider->setMinValue( 1);
140 Hour_Slider->setValue( i_alarmHour);
141 Minute_Slider->setValue( alarmMinute.toInt(&ok,10) );
142 SnoozeSlider->setValue( snoozeTime.toInt(&ok,10) );
143 Am_RadioButton->hide();
144 Pm_RadioButton->hide();
145 }
146 // signals and slots connections
147}
148
149Set_Alarm::~Set_Alarm()
150{
151
152}
153
154void Set_Alarm::slotChangeHour(int hour)
155{
156 Hour_LCDNumber->display(hour);
157}
158
159void Set_Alarm::slotChangeMinute(int minute)
160{
161 Minute_LCDNumber->display(minute);
162}
163
164void Set_Alarm::slotChangeSnooze(int minute)
165{
166 Snooze_LCDNumber->display(minute);
167}
168
169void Set_Alarm::amButtonToggled(bool b)
170{
171 if ( b)
172 Pm_RadioButton->setChecked(FALSE);
173}
174
175void Set_Alarm::pmButtonToggled(bool b)
176{
177 if (b)
178 Am_RadioButton->setChecked(FALSE);
179}
180
181void Set_Alarm::cleanUp()
182{
183}
diff --git a/noncore/tools/clock/setAlarm.h b/noncore/tools/clock/setAlarm.h
new file mode 100644
index 0000000..7d63237
--- a/dev/null
+++ b/noncore/tools/clock/setAlarm.h
@@ -0,0 +1,57 @@
1 /***************************************************************************
2// setAlarm.h - description
3// -------------------
4// Created: Wed Mar 13 19:47:24 2002
5// copyright : (C) 2002 by ljp
6// email : ljp@llornkcor.com
7//
8***************************************************************************
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 ***************************************************************************/
14
15#ifndef SET_ALARM_H
16#define SET_ALARM_H
17
18#include <qvariant.h>
19#include <qdialog.h>
20
21class QVBoxLayout;
22class QHBoxLayout;
23class QGridLayout;
24class QLCDNumber;
25class QLabel;
26class QRadioButton;
27class QSlider;
28class QButtonGroup;
29
30class Set_Alarm : public QDialog
31{
32 Q_OBJECT
33
34public:
35 Set_Alarm( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
36 ~Set_Alarm();
37
38 QLabel *TextLabel1, *TextLabel2, *TextLabel3;
39 QSlider *Hour_Slider, *Minute_Slider, *SnoozeSlider;
40 QLCDNumber *Hour_LCDNumber, *Minute_LCDNumber, *Snooze_LCDNumber;
41
42 QRadioButton* Am_RadioButton;
43
44 QRadioButton* Pm_RadioButton;
45 QButtonGroup *ButtonGroup1;
46protected slots:
47 void slotChangeHour(int);
48 void slotChangeMinute(int);
49 void slotChangeSnooze(int);
50 void amButtonToggled(bool);
51 void pmButtonToggled(bool);
52 void cleanUp();
53protected:
54 QGridLayout* Set_AlarmLayout;
55};
56
57#endif // SET_ALARM_H