author | llornkcor <llornkcor> | 2002-05-31 12:12:02 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-05-31 12:12:02 (UTC) |
commit | dd08e7fa2ccbcc0489c17ed305b20a9a7d187161 (patch) (unidiff) | |
tree | 59399ddb7c89ad178c85e576018db9471d292b52 | |
parent | 40eac37ff82dd4499a95adb786eb063fd0b81584 (diff) | |
download | opie-dd08e7fa2ccbcc0489c17ed305b20a9a7d187161.zip opie-dd08e7fa2ccbcc0489c17ed305b20a9a7d187161.tar.gz opie-dd08e7fa2ccbcc0489c17ed305b20a9a7d187161.tar.bz2 |
add zeckes change in again *DOH*, and initialize some silly int's to get rid of silly compiler warnings
-rw-r--r-- | noncore/tools/clock/clock.cpp | 253 | ||||
-rw-r--r-- | noncore/tools/clock/clock.h | 2 |
2 files changed, 133 insertions, 122 deletions
diff --git a/noncore/tools/clock/clock.cpp b/noncore/tools/clock/clock.cpp index a85cc19..0a21146 100644 --- a/noncore/tools/clock/clock.cpp +++ b/noncore/tools/clock/clock.cpp | |||
@@ -1,71 +1,72 @@ | |||
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 | // code added and Copyright (C) by L. J. Potter <ljp@llornkcor.com> 2002 | ||
21 | 20 | ||
22 | #include "clock.h" | 21 | #include "clock.h" |
23 | #include "setAlarm.h" | 22 | #include "setAlarm.h" |
24 | 23 | ||
25 | #include <qpe/qpeapplication.h> | 24 | #include <qpe/qpeapplication.h> |
26 | #include <qpe/qcopenvelope_qws.h> | 25 | #include <qpe/qcopenvelope_qws.h> |
27 | #include <qpe/config.h> | 26 | #include <qpe/config.h> |
28 | #include <qpe/timestring.h> | 27 | #include <qpe/timestring.h> |
29 | #include <qpe/alarmserver.h> | 28 | #include <qpe/alarmserver.h> |
30 | #include <qpe/sound.h> | 29 | #include <qpe/sound.h> |
31 | #include <qpe/resource.h> | 30 | #include <qpe/resource.h> |
32 | #include <qsound.h> | 31 | #include <qsound.h> |
33 | #include <qtimer.h> | 32 | #include <qtimer.h> |
34 | 33 | ||
34 | #include <opie/oclickablelabel.h> | ||
35 | |||
35 | #include <qlcdnumber.h> | 36 | #include <qlcdnumber.h> |
36 | #include <qslider.h> | 37 | #include <qslider.h> |
37 | #include <qlabel.h> | 38 | #include <qlabel.h> |
38 | #include <qlayout.h> | 39 | #include <qlayout.h> |
39 | #include <qtimer.h> | 40 | #include <qtimer.h> |
40 | #include <qpushbutton.h> | 41 | #include <qpushbutton.h> |
41 | #include <qradiobutton.h> | 42 | #include <qradiobutton.h> |
42 | #include <qbuttongroup.h> | 43 | #include <qbuttongroup.h> |
43 | #include <qpainter.h> | 44 | #include <qpainter.h> |
44 | #include <qmessagebox.h> | 45 | #include <qmessagebox.h> |
45 | #include <qdatetime.h> | 46 | #include <qdatetime.h> |
46 | 47 | ||
47 | #include <math.h> | 48 | #include <math.h> |
48 | 49 | ||
49 | const double deg2rad = 0.017453292519943295769; // pi/180 | 50 | const double deg2rad = 0.017453292519943295769; // pi/180 |
50 | const int sw_prec = 2; | 51 | const int sw_prec = 2; |
51 | 52 | ||
52 | static void toggleScreenSaver( bool on ) | 53 | static void toggleScreenSaver( bool on ) |
53 | { | 54 | { |
54 | QCopEnvelope e("QPE/System", "setScreenSaverMode(int)" ); | 55 | QCopEnvelope e("QPE/System", "setScreenSaverMode(int)" ); |
55 | e << (on ? QPEApplication::Enable: QPEApplication::DisableSuspend ); | 56 | e << (on ? QPEApplication::Enable: QPEApplication::DisableSuspend ); |
56 | } | 57 | } |
57 | 58 | ||
58 | Clock::Clock( QWidget * parent, const char * name, WFlags f ) | 59 | Clock::Clock( QWidget * parent, const char * name, WFlags f ) |
59 | : QVBox( parent, name , f ) | 60 | : QVBox( parent, name , f ) |
60 | { | 61 | { |
61 | setSpacing( 4 ); | 62 | setSpacing( 4 ); |
62 | setMargin( 1 ); | 63 | setMargin( 1 ); |
63 | 64 | ||
64 | Config config( "qpe" ); | 65 | Config config( "qpe" ); |
65 | config.setGroup("Time"); | 66 | config.setGroup("Time"); |
66 | ampm = config.readBoolEntry( "AMPM", TRUE ); | 67 | ampm = config.readBoolEntry( "AMPM", TRUE ); |
67 | 68 | ||
68 | snoozeBtn = new QPushButton ( this); | 69 | snoozeBtn = new QPushButton ( this); |
69 | snoozeBtn->setText( tr( "Snooze" ) ); | 70 | snoozeBtn->setText( tr( "Snooze" ) ); |
70 | 71 | ||
71 | aclock = new AnalogClock( this ); | 72 | aclock = new AnalogClock( this ); |
@@ -84,25 +85,25 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f ) | |||
84 | ampmLabel = new QLabel( tr("PM"), hb ); | 85 | ampmLabel = new QLabel( tr("PM"), hb ); |
85 | ampmLabel->setFont( QFont( "Helvetica", 14, QFont::Bold ) ); | 86 | ampmLabel->setFont( QFont( "Helvetica", 14, QFont::Bold ) ); |
86 | ampmLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred ) ); | 87 | ampmLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred ) ); |
87 | ampmLabel->setAlignment( AlignLeft | AlignBottom ); | 88 | ampmLabel->setAlignment( AlignLeft | AlignBottom ); |
88 | space = new QWidget( hb ); | 89 | space = new QWidget( hb ); |
89 | 90 | ||
90 | date = new QLabel( this ); | 91 | date = new QLabel( this ); |
91 | date->setAlignment( AlignHCenter | AlignVCenter ); | 92 | date->setAlignment( AlignHCenter | AlignVCenter ); |
92 | date->setFont( QFont( "Helvetica", 14, QFont::Bold ) ); | 93 | date->setFont( QFont( "Helvetica", 14, QFont::Bold ) ); |
93 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); | 94 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); |
94 | 95 | ||
95 | QWidget *controls = new QWidget( this ); | 96 | QWidget *controls = new QWidget( this ); |
96 | QGridLayout *gl = new QGridLayout( controls, 2, 2, 6, 4 ); | 97 | QGridLayout *gl = new QGridLayout( controls, 3, 2, 6, 4 ); |
97 | 98 | ||
98 | QButtonGroup *grp = new QButtonGroup( controls ); | 99 | QButtonGroup *grp = new QButtonGroup( controls ); |
99 | grp->setRadioButtonExclusive( true ); | 100 | grp->setRadioButtonExclusive( true ); |
100 | grp->hide(); | 101 | grp->hide(); |
101 | 102 | ||
102 | clockRB = new QRadioButton ( tr( "Clock" ), controls ); | 103 | clockRB = new QRadioButton ( tr( "Clock" ), controls ); |
103 | gl->addWidget( clockRB, 0, 0 ); | 104 | gl->addWidget( clockRB, 0, 0 ); |
104 | grp->insert( clockRB ); | 105 | grp->insert( clockRB ); |
105 | 106 | ||
106 | swatchRB = new QRadioButton ( tr( "Stopwatch" ), controls ); | 107 | swatchRB = new QRadioButton ( tr( "Stopwatch" ), controls ); |
107 | gl->addWidget( swatchRB, 1, 0 ); | 108 | gl->addWidget( swatchRB, 1, 0 ); |
108 | grp->insert( swatchRB ); | 109 | grp->insert( swatchRB ); |
@@ -123,33 +124,38 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f ) | |||
123 | reset->setEnabled( FALSE ); | 124 | reset->setEnabled( FALSE ); |
124 | grp->insert( reset ); | 125 | grp->insert( reset ); |
125 | 126 | ||
126 | alarmOffBtn = new QPushButton ( controls ); | 127 | alarmOffBtn = new QPushButton ( controls ); |
127 | // alarmOffBtn->setMaximumSize(60,30); | 128 | // alarmOffBtn->setMaximumSize(60,30); |
128 | gl->addWidget( alarmOffBtn, 0, 2 ); | 129 | gl->addWidget( alarmOffBtn, 0, 2 ); |
129 | 130 | ||
130 | alarmBtn = new QPushButton ( controls ); | 131 | alarmBtn = new QPushButton ( controls ); |
131 | // alarmBtn->setMaximumSize(60,30); | 132 | // alarmBtn->setMaximumSize(60,30); |
132 | gl->addWidget( alarmBtn, 1, 2 ); | 133 | gl->addWidget( alarmBtn, 1, 2 ); |
133 | alarmBtn->setText( tr( "Set Alarm" ) ); | 134 | alarmBtn->setText( tr( "Set Alarm" ) ); |
134 | 135 | ||
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 | |||
135 | connect( set, SIGNAL( pressed() ), SLOT( slotSet() ) ); | 141 | connect( set, SIGNAL( pressed() ), SLOT( slotSet() ) ); |
136 | connect( reset, SIGNAL( clicked() ), SLOT( slotReset() ) ); | 142 | connect( reset, SIGNAL( clicked() ), SLOT( slotReset() ) ); |
137 | 143 | ||
138 | connect( alarmBtn, SIGNAL( clicked() ), SLOT( slotSetAlarm() ) ); | 144 | connect( alarmBtn, SIGNAL( clicked() ), SLOT( slotSetAlarm() ) ); |
139 | connect( snoozeBtn, SIGNAL( clicked() ), SLOT( slotSnooze() ) ); | 145 | connect( snoozeBtn, SIGNAL( clicked() ), SLOT( slotSnooze() ) ); |
140 | connect( alarmOffBtn, SIGNAL( clicked() ), SLOT( slotToggleAlarm() ) ); | 146 | connect( alarmOffBtn, SIGNAL( clicked() ), SLOT( slotToggleAlarm() ) ); |
141 | 147 | ||
142 | connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), | 148 | connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), |
143 | this, SLOT(appMessage(const QCString&, const QByteArray&)) ); | 149 | this, SLOT(appMessage(const QCString&, const QByteArray&)) ); |
144 | 150 | ||
145 | t = new QTimer( this ); | 151 | t = new QTimer( this ); |
146 | connect( t, SIGNAL( timeout() ), SLOT( updateClock() ) ); | 152 | connect( t, SIGNAL( timeout() ), SLOT( updateClock() ) ); |
147 | t->start( 1000 ); | 153 | t->start( 1000 ); |
148 | 154 | ||
149 | connect( qApp, SIGNAL( timeChanged() ), SLOT( updateClock() ) ); | 155 | connect( qApp, SIGNAL( timeChanged() ), SLOT( updateClock() ) ); |
150 | 156 | ||
151 | swatch_running = FALSE; | 157 | swatch_running = FALSE; |
152 | swatch_totalms = 0; | 158 | swatch_totalms = 0; |
153 | 159 | ||
154 | connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) ); | 160 | connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) ); |
155 | 161 | ||
@@ -159,178 +165,178 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f ) | |||
159 | tmp = config.readEntry("clockAlarmMinute",""); | 165 | tmp = config.readEntry("clockAlarmMinute",""); |
160 | minute = tmp.toInt(&ok,10); | 166 | minute = tmp.toInt(&ok,10); |
161 | 167 | ||
162 | if( config.readEntry("clockAlarmSet","FALSE") == "TRUE") { | 168 | if( config.readEntry("clockAlarmSet","FALSE") == "TRUE") { |
163 | alarmOffBtn->setText( tr( "Alarm Is On" ) ); | 169 | alarmOffBtn->setText( tr( "Alarm Is On" ) ); |
164 | alarmBool=TRUE; | 170 | alarmBool=TRUE; |
165 | snoozeBtn->show(); | 171 | snoozeBtn->show(); |
166 | } else { | 172 | } else { |
167 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); | 173 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); |
168 | alarmBool=FALSE; | 174 | alarmBool=FALSE; |
169 | snoozeBtn->hide(); | 175 | snoozeBtn->hide(); |
170 | } | 176 | } |
171 | 177 | ||
172 | QTimer::singleShot( 0, this, SLOT(updateClock()) ); | 178 | QTimer::singleShot( 0, this, SLOT(updateClock()) ); |
173 | modeSelect(0); | 179 | modeSelect(0); |
174 | } | 180 | } |
175 | 181 | ||
176 | Clock::~Clock() | 182 | Clock::~Clock() |
177 | { | 183 | { |
178 | toggleScreenSaver( true ); | 184 | toggleScreenSaver( true ); |
179 | } | 185 | } |
180 | 186 | ||
181 | void Clock::updateClock() | 187 | void Clock::updateClock() |
182 | { | 188 | { |
183 | if ( clockRB->isChecked() ) { | 189 | if ( clockRB->isChecked() ) { |
184 | QTime tm = QDateTime::currentDateTime().time(); | 190 | QTime tm = QDateTime::currentDateTime().time(); |
185 | QString s; | 191 | QString s; |
186 | if ( ampm ) { | 192 | if ( ampm ) { |
187 | int hour = tm.hour(); | 193 | int hour = tm.hour(); |
188 | if (hour == 0) | 194 | if (hour == 0) |
189 | hour = 12; | 195 | hour = 12; |
190 | if (hour > 12) | 196 | if (hour > 12) |
191 | hour -= 12; | 197 | hour -= 12; |
192 | s.sprintf( "%2d%c%02d", hour, ':', tm.minute() ); | 198 | s.sprintf( "%2d%c%02d", hour, ':', tm.minute() ); |
193 | ampmLabel->setText( (tm.hour() >= 12) ? "PM" : "AM" ); | 199 | ampmLabel->setText( (tm.hour() >= 12) ? "PM" : "AM" ); |
194 | ampmLabel->show(); | 200 | ampmLabel->show(); |
195 | } else { | 201 | } else { |
196 | s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() ); | 202 | s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() ); |
197 | ampmLabel->hide(); | 203 | ampmLabel->hide(); |
198 | } | 204 | } |
199 | lcd->display( s ); | 205 | lcd->display( s ); |
200 | lcd->repaint( FALSE ); | 206 | lcd->repaint( FALSE ); |
201 | aclock->display( QTime::currentTime() ); | 207 | aclock->display( QTime::currentTime() ); |
202 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); | 208 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); |
203 | } else { | 209 | } else { |
204 | QTime swatch_time; | 210 | QTime swatch_time; |
205 | QString lcdtext; | 211 | QString lcdtext; |
206 | int totalms = swatch_totalms; | 212 | int totalms = swatch_totalms; |
207 | if ( swatch_running ) | 213 | if ( swatch_running ) |
208 | totalms += swatch_start.elapsed(); | 214 | totalms += swatch_start.elapsed(); |
209 | swatch_time = QTime(0,0,0).addMSecs(totalms); | 215 | swatch_time = QTime(0,0,0).addMSecs(totalms); |
210 | QString d = swatch_running ? QString(" ") | 216 | QString d = swatch_running ? QString(" ") |
211 | : QString::number(totalms%1000+1000); | 217 | : QString::number(totalms%1000+1000); |
212 | lcdtext = swatch_time.toString() + "." + d.right(3).left(sw_prec); | 218 | lcdtext = swatch_time.toString() + "." + d.right(3).left(sw_prec); |
213 | lcd->display( lcdtext ); | 219 | lcd->display( lcdtext ); |
214 | lcd->repaint( FALSE ); | 220 | lcd->repaint( FALSE ); |
215 | aclock->display( swatch_time ); | 221 | aclock->display( swatch_time ); |
216 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); | 222 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); |
217 | } | 223 | } |
218 | } | 224 | } |
219 | 225 | ||
220 | void Clock::changeClock( bool a ) | 226 | void Clock::changeClock( bool a ) |
221 | { | 227 | { |
222 | ampm = a; | 228 | ampm = a; |
223 | updateClock(); | 229 | updateClock(); |
224 | } | 230 | } |
225 | 231 | ||
226 | void Clock::clearClock( void ) | 232 | void Clock::clearClock( void ) |
227 | { | 233 | { |
228 | lcd->display( QTime( 0,0,0 ).toString() ); | 234 | lcd->display( QTime( 0,0,0 ).toString() ); |
229 | aclock->display( QTime( 0,0,0 ) ); | 235 | aclock->display( QTime( 0,0,0 ) ); |
230 | } | 236 | } |
231 | 237 | ||
232 | void Clock::slotSet() | 238 | void Clock::slotSet() |
233 | { | 239 | { |
234 | if ( t->isActive() ) { | 240 | if ( t->isActive() ) { |
235 | swatch_totalms += swatch_start.elapsed(); | 241 | swatch_totalms += swatch_start.elapsed(); |
236 | set->setText( tr( "Start" ) ); | 242 | set->setText( tr( "Start" ) ); |
237 | t->stop(); | 243 | t->stop(); |
238 | swatch_running = FALSE; | 244 | swatch_running = FALSE; |
239 | toggleScreenSaver( TRUE ); | 245 | toggleScreenSaver( TRUE ); |
240 | updateClock(); | 246 | updateClock(); |
241 | } else { | 247 | } else { |
242 | swatch_start.start(); | 248 | swatch_start.start(); |
243 | set->setText( tr( "Stop" ) ); | 249 | set->setText( tr( "Stop" ) ); |
244 | t->start( 1000 ); | 250 | t->start( 1000 ); |
245 | swatch_running = TRUE; | 251 | swatch_running = TRUE; |
246 | // disable screensaver while stop watch is running | 252 | // disable screensaver while stop watch is running |
247 | toggleScreenSaver( FALSE ); | 253 | toggleScreenSaver( FALSE ); |
248 | } | 254 | } |
249 | } | 255 | } |
250 | 256 | ||
251 | void Clock::slotReset() | 257 | void Clock::slotReset() |
252 | { | 258 | { |
253 | t->stop(); | 259 | t->stop(); |
254 | swatch_start.start(); | 260 | swatch_start.start(); |
255 | swatch_totalms = 0; | 261 | swatch_totalms = 0; |
256 | 262 | ||
257 | if (swatch_running ) | 263 | if (swatch_running ) |
258 | t->start(1000); | 264 | t->start(1000); |
259 | 265 | ||
260 | updateClock(); | 266 | updateClock(); |
261 | } | 267 | } |
262 | 268 | ||
263 | void Clock::modeSelect( int m ) | 269 | void Clock::modeSelect( int m ) |
264 | { | 270 | { |
265 | if ( m ) { | 271 | if ( m ) { |
266 | lcd->setNumDigits( 8+1+sw_prec ); | 272 | lcd->setNumDigits( 8+1+sw_prec ); |
267 | lcd->setMinimumWidth( lcd->sizeHint().width() ); | 273 | lcd->setMinimumWidth( lcd->sizeHint().width() ); |
268 | set->setEnabled( TRUE ); | 274 | set->setEnabled( TRUE ); |
269 | reset->setEnabled( TRUE ); | 275 | reset->setEnabled( TRUE ); |
270 | ampmLabel->hide(); | 276 | ampmLabel->hide(); |
271 | 277 | ||
272 | if ( !swatch_running ) | 278 | if ( !swatch_running ) |
273 | t->stop(); | 279 | t->stop(); |
274 | } else { | 280 | } else { |
275 | lcd->setNumDigits( 5 ); | 281 | lcd->setNumDigits( 5 ); |
276 | lcd->setMinimumWidth( lcd->sizeHint().width() ); | 282 | lcd->setMinimumWidth( lcd->sizeHint().width() ); |
277 | set->setEnabled( FALSE ); | 283 | set->setEnabled( FALSE ); |
278 | reset->setEnabled( FALSE ); | 284 | reset->setEnabled( FALSE ); |
279 | t->start(1000); | 285 | t->start(1000); |
280 | } | 286 | } |
281 | updateClock(); | 287 | updateClock(); |
282 | } | 288 | } |
283 | 289 | ||
284 | //this sets the alarm time | 290 | //this sets the alarm time |
285 | void Clock::slotSetAlarm() | 291 | void Clock::slotSetAlarm() |
286 | { | 292 | { |
287 | if( !snoozeBtn->isHidden()) | 293 | if( !snoozeBtn->isHidden()) |
288 | slotToggleAlarm(); | 294 | slotToggleAlarm(); |
289 | Set_Alarm *setAlarmDlg; | 295 | Set_Alarm *setAlarmDlg; |
290 | setAlarmDlg = new Set_Alarm(this,"SetAlarm", TRUE); | 296 | setAlarmDlg = new Set_Alarm(this,"SetAlarm", TRUE); |
291 | int result = setAlarmDlg->exec(); | 297 | int result = setAlarmDlg->exec(); |
292 | if(result == 1) { | 298 | if(result == 1) { |
293 | Config config( "qpe" ); | 299 | Config config( "qpe" ); |
294 | config.setGroup("Time"); | 300 | config.setGroup("Time"); |
295 | QString tmp; | 301 | QString tmp; |
296 | hour = setAlarmDlg->Hour_Slider->value(); | 302 | hour = setAlarmDlg->Hour_Slider->value(); |
297 | minute = setAlarmDlg->Minute_Slider->value(); | 303 | minute = setAlarmDlg->Minute_Slider->value(); |
298 | snoozeTime=setAlarmDlg->SnoozeSlider->value(); | 304 | snoozeTime=setAlarmDlg->SnoozeSlider->value(); |
299 | if(ampm) { | 305 | if(ampm) { |
300 | if(setAlarmDlg->Pm_RadioButton->isChecked() && hour < 12 ) | 306 | if(setAlarmDlg->Pm_RadioButton->isChecked() && hour < 12 ) |
301 | hour+=12; | 307 | hour+=12; |
302 | } | 308 | } |
303 | config.writeEntry("clockAlarmHour", tmp.setNum( hour ),10); | 309 | config.writeEntry("clockAlarmHour", tmp.setNum( hour ),10); |
304 | config.writeEntry("clockAlarmMinute",tmp.setNum( minute ),10); | 310 | config.writeEntry("clockAlarmMinute",tmp.setNum( minute ),10); |
305 | config.writeEntry("clockAlarmSnooze",tmp.setNum( snoozeTime ),10); | 311 | config.writeEntry("clockAlarmSnooze",tmp.setNum( snoozeTime ),10); |
306 | config.write(); | 312 | config.write(); |
307 | } | 313 | } |
308 | } | 314 | } |
309 | 315 | ||
310 | void Clock::slotSnooze() | 316 | void Clock::slotSnooze() |
311 | { | 317 | { |
312 | bSound=FALSE; | 318 | bSound=FALSE; |
313 | int warn; | 319 | int warn = 0; |
314 | QTime t = QTime::currentTime(); | 320 | QTime t = QTime::currentTime(); |
315 | QDateTime whenl( when.date(), t.addSecs( snoozeTime*60)); | 321 | QDateTime whenl( when.date(), t.addSecs( snoozeTime*60)); |
316 | when=whenl; | 322 | when=whenl; |
317 | AlarmServer::addAlarm( when, | 323 | AlarmServer::addAlarm( when, |
318 | "QPE/Application/clock", | 324 | "QPE/Application/clock", |
319 | "alarm(QDateTime,int)", warn ); | 325 | "alarm(QDateTime,int)", warn ); |
320 | 326 | ||
321 | } | 327 | } |
322 | 328 | ||
323 | //toggles alarm on/off | 329 | //toggles alarm on/off |
324 | void Clock::slotToggleAlarm() | 330 | void Clock::slotToggleAlarm() |
325 | { | 331 | { |
326 | Config config( "qpe" ); | 332 | Config config( "qpe" ); |
327 | config.setGroup("Time"); | 333 | config.setGroup("Time"); |
328 | if(alarmBool) { | 334 | if(alarmBool) { |
329 | config.writeEntry("clockAlarmSet","FALSE"); | 335 | config.writeEntry("clockAlarmSet","FALSE"); |
330 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); | 336 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); |
331 | snoozeBtn->hide(); | 337 | snoozeBtn->hide(); |
332 | alarmBool=FALSE; | 338 | alarmBool=FALSE; |
333 | alarmOff(); | 339 | alarmOff(); |
334 | } else { | 340 | } else { |
335 | config.writeEntry("clockAlarmSet","TRUE"); | 341 | config.writeEntry("clockAlarmSet","TRUE"); |
336 | alarmOffBtn->setText( tr( "Alarm Is On" ) ); | 342 | alarmOffBtn->setText( tr( "Alarm Is On" ) ); |
@@ -340,53 +346,53 @@ void Clock::slotToggleAlarm() | |||
340 | } | 346 | } |
341 | config.write(); | 347 | config.write(); |
342 | } | 348 | } |
343 | 349 | ||
344 | void Clock::alarmOn() | 350 | void Clock::alarmOn() |
345 | { | 351 | { |
346 | QDate d = QDate::currentDate(); | 352 | QDate d = QDate::currentDate(); |
347 | QTime tm((int)hour,(int)minute,0); | 353 | QTime tm((int)hour,(int)minute,0); |
348 | qDebug("Time set "+tm.toString()); | 354 | qDebug("Time set "+tm.toString()); |
349 | QTime t = QTime::currentTime(); | 355 | QTime t = QTime::currentTime(); |
350 | if( t > tm) | 356 | if( t > tm) |
351 | d = d.addDays(1); | 357 | d = d.addDays(1); |
352 | int warn; | 358 | int warn = 0; |
353 | QDateTime whenl(d,tm); | 359 | QDateTime whenl(d,tm); |
354 | when=whenl; | 360 | when=whenl; |
355 | AlarmServer::addAlarm( when, | 361 | AlarmServer::addAlarm( when, |
356 | "QPE/Application/clock", | 362 | "QPE/Application/clock", |
357 | "alarm(QDateTime,int)", warn ); | 363 | "alarm(QDateTime,int)", warn ); |
358 | setCaption("Alarm set: "+ whenl.toString()); | 364 | setCaption("Alarm set: "+ whenl.toString()); |
359 | } | 365 | } |
360 | 366 | ||
361 | void Clock::alarmOff() | 367 | void Clock::alarmOff() |
362 | { | 368 | { |
363 | int warn; | 369 | int warn = 0; |
364 | bSound=FALSE; | 370 | bSound=FALSE; |
365 | AlarmServer::deleteAlarm( when, | 371 | AlarmServer::deleteAlarm( when, |
366 | "QPE/Application/clock", | 372 | "QPE/Application/clock", |
367 | "alarm(QDateTime,int)", warn ); | 373 | "alarm(QDateTime,int)", warn ); |
368 | qDebug("Alarm Off "+ when.toString()); | 374 | qDebug("Alarm Off "+ when.toString()); |
369 | setCaption("Clock"); | 375 | setCaption("Clock"); |
370 | } | 376 | } |
371 | 377 | ||
372 | void Clock::appMessage(const QCString& msg, const QByteArray& data) | 378 | void Clock::appMessage(const QCString& msg, const QByteArray& data) |
373 | { | 379 | { |
374 | int stopTimer = 0; | 380 | int stopTimer = 0; |
375 | int timerStay = 5000; | 381 | int timerStay = 5000; |
376 | bSound=TRUE; | 382 | bSound=TRUE; |
377 | if ( msg == "alarm(QDateTime,int)" ) { | 383 | if ( msg == "alarm(QDateTime,int)" ) { |
378 | Sound::soundAlarm(); | 384 | Sound::soundAlarm(); |
379 | stopTimer = startTimer( timerStay); | 385 | stopTimer = startTimer( timerStay); |
380 | } | 386 | } |
381 | } | 387 | } |
382 | 388 | ||
383 | void Clock::timerEvent( QTimerEvent *e ) | 389 | void Clock::timerEvent( QTimerEvent *e ) |
384 | { | 390 | { |
385 | static int stop = 0; | 391 | static int stop = 0; |
386 | if ( stop < 120 && bSound) { | 392 | if ( stop < 120 && bSound) { |
387 | Sound::soundAlarm(); | 393 | Sound::soundAlarm(); |
388 | stop++; | 394 | stop++; |
389 | } else { | 395 | } else { |
390 | stop = 0; | 396 | stop = 0; |
391 | killTimer( e->timerId() ); | 397 | killTimer( e->timerId() ); |
392 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); | 398 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); |
@@ -414,68 +420,73 @@ void AnalogClock::drawContents( QPainter *p ) | |||
414 | QPoint h2( r.x() + r.width() / 2, r.y() + r.height() / 2 ); | 420 | QPoint h2( r.x() + r.width() / 2, r.y() + r.height() / 2 ); |
415 | 421 | ||
416 | QPoint m1( r.x() + r.width() / 2, r.y() + r.height() / 8 ); | 422 | QPoint m1( r.x() + r.width() / 2, r.y() + r.height() / 8 ); |
417 | QPoint m2( r.x() + r.width() / 2, r.y() + r.height() / 2 ); | 423 | QPoint m2( r.x() + r.width() / 2, r.y() + r.height() / 2 ); |
418 | 424 | ||
419 | QPoint s1( r.x() + r.width() / 2, r.y() + 8 ); | 425 | QPoint s1( r.x() + r.width() / 2, r.y() + 8 ); |
420 | QPoint s2( r.x() + r.width() / 2, r.y() + r.height() / 2 ); | 426 | QPoint s2( r.x() + r.width() / 2, r.y() + r.height() / 2 ); |
421 | 427 | ||
422 | QColor color( clear ? backgroundColor() : black ); | 428 | QColor color( clear ? backgroundColor() : black ); |
423 | QTime time = clear ? prevTime : currTime; | 429 | QTime time = clear ? prevTime : currTime; |
424 | 430 | ||
425 | if ( clear && prevTime.secsTo(currTime) > 1 ) { | 431 | if ( clear && prevTime.secsTo(currTime) > 1 ) { |
426 | p->eraseRect( rect() ); | 432 | p->eraseRect( rect() ); |
427 | return; | 433 | return; |
428 | } | 434 | } |
429 | 435 | ||
430 | if ( !clear ) { | 436 | if ( !clear ) { |
431 | // draw ticks | 437 | // draw ticks |
432 | p->setPen( QPen( color, 1 ) ); | 438 | p->setPen( QPen( color, 1 ) ); |
433 | for ( int i = 0; i < 12; i++ ) | 439 | for ( int i = 0; i < 12; i++ ) |
434 | p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) ); | 440 | p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) ); |
435 | } | 441 | } |
436 | 442 | ||
437 | if ( !clear || prevTime.minute() != currTime.minute() || | 443 | if ( !clear || prevTime.minute() != currTime.minute() || |
438 | prevTime.hour() != currTime.hour() ) { | 444 | prevTime.hour() != currTime.hour() ) { |
439 | // draw hour pointer | 445 | // draw hour pointer |
440 | h1 = rotate( center, h1, 30 * ( time.hour() % 12 ) + time.minute() / 2 ); | 446 | h1 = rotate( center, h1, 30 * ( time.hour() % 12 ) + time.minute() / 2 ); |
441 | h2 = rotate( center, h2, 30 * ( time.hour() % 12 ) + time.minute() / 2 ); | 447 | h2 = rotate( center, h2, 30 * ( time.hour() % 12 ) + time.minute() / 2 ); |
442 | p->setPen( QPen( color, 3 ) ); | 448 | p->setPen( QPen( color, 3 ) ); |
443 | p->drawLine( h1, h2 ); | 449 | p->drawLine( h1, h2 ); |
444 | } | 450 | } |
445 | 451 | ||
446 | if ( !clear || prevTime.minute() != currTime.minute() ) { | 452 | if ( !clear || prevTime.minute() != currTime.minute() ) { |
447 | // draw minute pointer | 453 | // draw minute pointer |
448 | m1 = rotate( center, m1, time.minute() * 6 ); | 454 | m1 = rotate( center, m1, time.minute() * 6 ); |
449 | m2 = rotate( center, m2, time.minute() * 6 ); | 455 | m2 = rotate( center, m2, time.minute() * 6 ); |
450 | p->setPen( QPen( color, 2 ) ); | 456 | p->setPen( QPen( color, 2 ) ); |
451 | p->drawLine( m1, m2 ); | 457 | p->drawLine( m1, m2 ); |
452 | } | 458 | } |
453 | 459 | ||
454 | // draw second pointer | 460 | // draw second pointer |
455 | s1 = rotate( center, s1, time.second() * 6 ); | 461 | s1 = rotate( center, s1, time.second() * 6 ); |
456 | s2 = rotate( center, s2, time.second() * 6 ); | 462 | s2 = rotate( center, s2, time.second() * 6 ); |
457 | p->setPen( QPen( color, 1 ) ); | 463 | p->setPen( QPen( color, 1 ) ); |
458 | p->drawLine( s1, s2 ); | 464 | p->drawLine( s1, s2 ); |
459 | 465 | ||
460 | if ( !clear ) | 466 | if ( !clear ) |
461 | prevTime = currTime; | 467 | prevTime = currTime; |
462 | } | 468 | } |
463 | 469 | ||
464 | void AnalogClock::display( const QTime& t ) | 470 | void AnalogClock::display( const QTime& t ) |
465 | { | 471 | { |
466 | currTime = t; | 472 | currTime = t; |
467 | clear = true; | 473 | clear = true; |
468 | repaint( false ); | 474 | repaint( false ); |
469 | clear = false; | 475 | clear = false; |
470 | repaint( false ); | 476 | repaint( false ); |
471 | } | 477 | } |
472 | 478 | ||
473 | QPoint AnalogClock::rotate( QPoint c, QPoint p, int a ) | 479 | QPoint AnalogClock::rotate( QPoint c, QPoint p, int a ) |
474 | { | 480 | { |
475 | double angle = deg2rad * ( - a + 180 ); | 481 | double angle = deg2rad * ( - a + 180 ); |
476 | double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) - | 482 | double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) - |
477 | ( p.y() - c.y() ) * sin( angle ); | 483 | ( p.y() - c.y() ) * sin( angle ); |
478 | double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) + | 484 | double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) + |
479 | ( p.x() - c.x() ) * sin( angle ); | 485 | ( p.x() - c.x() ) * sin( angle ); |
480 | return QPoint( nx, ny ); | 486 | return QPoint( nx, ny ); |
481 | } | 487 | } |
488 | void Clock::slotAdjustTime() | ||
489 | { | ||
490 | QCopEnvelope e("QPE/System", "execute(QString)"); | ||
491 | e << QString("systemtime"); | ||
492 | } | ||
diff --git a/noncore/tools/clock/clock.h b/noncore/tools/clock/clock.h index e5ed13c..024dd28 100644 --- a/noncore/tools/clock/clock.h +++ b/noncore/tools/clock/clock.h | |||
@@ -67,25 +67,25 @@ private 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 | 80 | ||
81 | private: | 81 | private: |
82 | void clearClock(); | 82 | void clearClock(); |
83 | 83 | ||
84 | bool alarmBool; | 84 | bool alarmBool; |
85 | QTimer *t; | 85 | QTimer *t; |
86 | QLCDNumber *lcd; | 86 | QLCDNumber *lcd; |
87 | QLabel *date; | 87 | QLabel *date; |
88 | QLabel *ampmLabel; | 88 | QLabel *ampmLabel; |
89 | QPushButton *set, *reset, *alarmBtn, *snoozeBtn, *alarmOffBtn; | 89 | QPushButton *set, *reset, *alarmBtn, *snoozeBtn, *alarmOffBtn; |
90 | QRadioButton *clockRB, *swatchRB; | 90 | QRadioButton *clockRB, *swatchRB; |
91 | AnalogClock *aclock; | 91 | AnalogClock *aclock; |