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