-rw-r--r-- | noncore/tools/clock/clock.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/tools/clock/clock.cpp b/noncore/tools/clock/clock.cpp index 118cf1f..b780675 100644 --- a/noncore/tools/clock/clock.cpp +++ b/noncore/tools/clock/clock.cpp | |||
@@ -1,663 +1,663 @@ | |||
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 <opie2/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 | #include <unistd.h> | 50 | #include <unistd.h> |
51 | #include <sys/types.h> | 51 | #include <sys/types.h> |
52 | 52 | ||
53 | #include <pthread.h> | 53 | #include <pthread.h> |
54 | 54 | ||
55 | 55 | ||
56 | const double deg2rad = 0.017453292519943295769; // pi/180 | 56 | const double deg2rad = 0.017453292519943295769; // pi/180 |
57 | const int sw_prec = 2; | 57 | const int sw_prec = 2; |
58 | 58 | ||
59 | void startPlayer() | 59 | void startPlayer() |
60 | { | 60 | { |
61 | Config config( "qpe" ); | 61 | Config config( "qpe" ); |
62 | config.setGroup( "Time" ); | 62 | config.setGroup( "Time" ); |
63 | sleep(15); | 63 | sleep(15); |
64 | QCopEnvelope e( "QPE/Application/opieplayer", "setDocument(QString)" ); | 64 | QCopEnvelope e( "QPE/Application/opieplayer", "setDocument(QString)" ); |
65 | e << config.readEntry( "mp3File", "" ); | 65 | e << config.readEntry( "mp3File", "" ); |
66 | } | 66 | } |
67 | 67 | ||
68 | 68 | ||
69 | static void toggleScreenSaver( bool on ) | 69 | static void toggleScreenSaver( bool on ) |
70 | { | 70 | { |
71 | QCopEnvelope e( "QPE/System", "setScreenSaverMode(int)" ); | 71 | QCopEnvelope e( "QPE/System", "setScreenSaverMode(int)" ); |
72 | e << ( on ? QPEApplication::Enable : QPEApplication::DisableSuspend ); | 72 | e << ( on ? QPEApplication::Enable : QPEApplication::DisableSuspend ); |
73 | } | 73 | } |
74 | 74 | ||
75 | Clock::Clock( QWidget * parent, const char * name, WFlags f ) | 75 | Clock::Clock( QWidget * parent, const char * name, WFlags f ) |
76 | : QVBox( parent, name , f ) | 76 | : QVBox( parent, name , f ) |
77 | { | 77 | { |
78 | setSpacing( 4 ); | 78 | setSpacing( 4 ); |
79 | setMargin( 1 ); | 79 | setMargin( 1 ); |
80 | 80 | ||
81 | 81 | ||
82 | snoozeBtn = new QPushButton ( this ); | 82 | snoozeBtn = new QPushButton ( this ); |
83 | snoozeBtn->setText( tr( "Snooze" ) ); | 83 | snoozeBtn->setText( tr( "Snooze" ) ); |
84 | 84 | ||
85 | aclock = new AnalogClock( this ); | 85 | aclock = new AnalogClock( this ); |
86 | aclock->display( QTime::currentTime() ); | 86 | aclock->display( QTime::currentTime() ); |
87 | aclock->setLineWidth( 2 ); | 87 | aclock->setLineWidth( 2 ); |
88 | 88 | ||
89 | QHBox *hb = new QHBox( this ); | 89 | QHBox *hb = new QHBox( this ); |
90 | hb->setMargin( 0 ); | 90 | hb->setMargin( 0 ); |
91 | QWidget *space = new QWidget( hb ); | 91 | QWidget *space = new QWidget( hb ); |
92 | lcd = new QLCDNumber( hb ); | 92 | lcd = new QLCDNumber( hb ); |
93 | lcd->setSegmentStyle( QLCDNumber::Flat ); | 93 | lcd->setSegmentStyle( QLCDNumber::Flat ); |
94 | lcd->setFrameStyle( QFrame::NoFrame ); | 94 | lcd->setFrameStyle( QFrame::NoFrame ); |
95 | lcd->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) ); | 95 | lcd->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) ); |
96 | lcd->setFixedHeight( 23 ); | 96 | lcd->setFixedHeight( 23 ); |
97 | 97 | ||
98 | ampmLabel = new QLabel( tr( "PM" ), hb ); | 98 | ampmLabel = new QLabel( tr( "PM" ), hb ); |
99 | ampmLabel->setFont( QFont( "Helvetica", 14, QFont::Bold ) ); | 99 | ampmLabel->setFont( QFont( "Helvetica", 14, QFont::Bold ) ); |
100 | ampmLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred ) ); | 100 | ampmLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred ) ); |
101 | ampmLabel->setAlignment( AlignLeft | AlignBottom ); | 101 | ampmLabel->setAlignment( AlignLeft | AlignBottom ); |
102 | space = new QWidget( hb ); | 102 | space = new QWidget( hb ); |
103 | 103 | ||
104 | date = new QLabel( this ); | 104 | date = new QLabel( this ); |
105 | date->setAlignment( AlignHCenter | AlignVCenter ); | 105 | date->setAlignment( AlignHCenter | AlignVCenter ); |
106 | date->setFont( QFont( "Helvetica", 14, QFont::Bold ) ); | 106 | date->setFont( QFont( "Helvetica", 14, QFont::Bold ) ); |
107 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); | 107 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); |
108 | 108 | ||
109 | QWidget *controls = new QWidget( this ); | 109 | QWidget *controls = new QWidget( this ); |
110 | QGridLayout *gl = new QGridLayout( controls, 3, 2, 6, 4 ); | 110 | QGridLayout *gl = new QGridLayout( controls, 3, 2, 6, 4 ); |
111 | 111 | ||
112 | QButtonGroup *grp = new QButtonGroup( controls ); | 112 | QButtonGroup *grp = new QButtonGroup( controls ); |
113 | grp->setRadioButtonExclusive( true ); | 113 | grp->setRadioButtonExclusive( true ); |
114 | grp->hide(); | 114 | grp->hide(); |
115 | 115 | ||
116 | clockRB = new QRadioButton ( tr( "Clock" ), controls ); | 116 | clockRB = new QRadioButton ( tr( "Clock" ), controls ); |
117 | gl->addWidget( clockRB, 0, 0 ); | 117 | gl->addWidget( clockRB, 0, 0 ); |
118 | grp->insert( clockRB ); | 118 | grp->insert( clockRB ); |
119 | 119 | ||
120 | swatchRB = new QRadioButton ( tr( "Stopwatch" ), controls ); | 120 | swatchRB = new QRadioButton ( tr( "Stopwatch" ), controls ); |
121 | gl->addWidget( swatchRB, 1, 0 ); | 121 | gl->addWidget( swatchRB, 1, 0 ); |
122 | grp->insert( swatchRB ); | 122 | grp->insert( swatchRB ); |
123 | 123 | ||
124 | connect( grp, SIGNAL( clicked(int) ), this, SLOT( modeSelect(int) ) ); | 124 | connect( grp, SIGNAL( clicked(int) ), this, SLOT( modeSelect(int) ) ); |
125 | grp->setButton( 0 ); | 125 | grp->setButton( 0 ); |
126 | 126 | ||
127 | set = new QPushButton ( controls ); | 127 | set = new QPushButton ( controls ); |
128 | set->setMaximumSize( 50, 30 ); | 128 | set->setMaximumSize( 50, 30 ); |
129 | gl->addWidget( set , 0, 1 ); | 129 | gl->addWidget( set , 0, 1 ); |
130 | set->setText( tr( "Start" ) ); | 130 | set->setText( tr( "Start" ) ); |
131 | set->setEnabled( FALSE ); | 131 | set->setEnabled( FALSE ); |
132 | grp->insert( set ); | 132 | grp->insert( set ); |
133 | 133 | ||
134 | reset = new QPushButton ( controls ); | 134 | reset = new QPushButton ( controls ); |
135 | gl->addWidget( reset, 1, 1 ); | 135 | gl->addWidget( reset, 1, 1 ); |
136 | reset->setText( tr( "Reset" ) ); | 136 | reset->setText( tr( "Reset" ) ); |
137 | reset->setEnabled( FALSE ); | 137 | reset->setEnabled( FALSE ); |
138 | grp->insert( reset ); | 138 | grp->insert( reset ); |
139 | 139 | ||
140 | alarmOffBtn = new QPushButton ( controls ); | 140 | alarmOffBtn = new QPushButton ( controls ); |
141 | gl->addWidget( alarmOffBtn, 0, 2 ); | 141 | gl->addWidget( alarmOffBtn, 0, 2 ); |
142 | 142 | ||
143 | alarmBtn = new QPushButton ( controls ); | 143 | alarmBtn = new QPushButton ( controls ); |
144 | gl->addWidget( alarmBtn, 1, 2 ); | 144 | gl->addWidget( alarmBtn, 1, 2 ); |
145 | 145 | ||
146 | alarmBtn->setText( tr( "Set Alarm" ) ); | 146 | alarmBtn->setText( tr( "Set Alarm" ) ); |
147 | 147 | ||
148 | OClickableLabel *click = new OClickableLabel( controls, "label" ); | 148 | Opie::OClickableLabel *click = new Opie::OClickableLabel( controls, "label" ); |
149 | click->setText( tr( "Set date and time." ) ); | 149 | click->setText( tr( "Set date and time." ) ); |
150 | gl->addMultiCellWidget( click, 3, 3, 0, 2, AlignHCenter ); | 150 | gl->addMultiCellWidget( click, 3, 3, 0, 2, AlignHCenter ); |
151 | connect( click, SIGNAL( clicked() ), this, SLOT( slotAdjustTime() ) ); | 151 | connect( click, SIGNAL( clicked() ), this, SLOT( slotAdjustTime() ) ); |
152 | 152 | ||
153 | connect( set , SIGNAL( pressed() ), SLOT( slotSet() ) ); | 153 | connect( set , SIGNAL( pressed() ), SLOT( slotSet() ) ); |
154 | connect( reset, SIGNAL( clicked() ), SLOT( slotReset() ) ); | 154 | connect( reset, SIGNAL( clicked() ), SLOT( slotReset() ) ); |
155 | 155 | ||
156 | connect( alarmBtn, SIGNAL( clicked() ), SLOT( slotSetAlarm() ) ); | 156 | connect( alarmBtn, SIGNAL( clicked() ), SLOT( slotSetAlarm() ) ); |
157 | connect( snoozeBtn, SIGNAL( clicked() ), SLOT( slotSnooze() ) ); | 157 | connect( snoozeBtn, SIGNAL( clicked() ), SLOT( slotSnooze() ) ); |
158 | connect( alarmOffBtn, SIGNAL( clicked() ), SLOT( slotToggleAlarm() ) ); | 158 | connect( alarmOffBtn, SIGNAL( clicked() ), SLOT( slotToggleAlarm() ) ); |
159 | 159 | ||
160 | connect( qApp, SIGNAL( appMessage(const QCString&,const QByteArray&) ), | 160 | connect( qApp, SIGNAL( appMessage(const QCString&,const QByteArray&) ), |
161 | this, SLOT( appMessage(const QCString&,const QByteArray&) ) ); | 161 | this, SLOT( appMessage(const QCString&,const QByteArray&) ) ); |
162 | 162 | ||
163 | t = new QTimer( this ); | 163 | t = new QTimer( this ); |
164 | connect( t, SIGNAL( timeout() ), SLOT( updateClock() ) ); | 164 | connect( t, SIGNAL( timeout() ), SLOT( updateClock() ) ); |
165 | t->start( 1000 ); | 165 | t->start( 1000 ); |
166 | 166 | ||
167 | connect( qApp, SIGNAL( timeChanged() ), SLOT( updateClock() ) ); | 167 | connect( qApp, SIGNAL( timeChanged() ), SLOT( updateClock() ) ); |
168 | 168 | ||
169 | swatch_running = FALSE; | 169 | swatch_running = FALSE; |
170 | swatch_totalms = 0; | 170 | swatch_totalms = 0; |
171 | 171 | ||
172 | connect( qApp, SIGNAL( clockChanged(bool) ), this, SLOT( changeClock(bool) ) ); | 172 | connect( qApp, SIGNAL( clockChanged(bool) ), this, SLOT( changeClock(bool) ) ); |
173 | 173 | ||
174 | 174 | ||
175 | Config config( "qpe" ); | 175 | Config config( "qpe" ); |
176 | config.setGroup( "Time" ); | 176 | config.setGroup( "Time" ); |
177 | ampm = config.readBoolEntry( "AMPM", TRUE ); | 177 | ampm = config.readBoolEntry( "AMPM", TRUE ); |
178 | 178 | ||
179 | QString tmp = config.readEntry( "clockAlarmHour", "" ); | 179 | QString tmp = config.readEntry( "clockAlarmHour", "" ); |
180 | bool ok; | 180 | bool ok; |
181 | hour = tmp.toInt( &ok, 10 ); | 181 | hour = tmp.toInt( &ok, 10 ); |
182 | tmp = config.readEntry( "clockAlarmMinute", "" ); | 182 | tmp = config.readEntry( "clockAlarmMinute", "" ); |
183 | minute = tmp.toInt( &ok, 10 ); | 183 | minute = tmp.toInt( &ok, 10 ); |
184 | 184 | ||
185 | if ( config.readEntry( "clockAlarmSet", "FALSE" ) == "TRUE" ) | 185 | if ( config.readEntry( "clockAlarmSet", "FALSE" ) == "TRUE" ) |
186 | { | 186 | { |
187 | alarmOffBtn->setText( tr( "Alarm Is On" ) ); | 187 | alarmOffBtn->setText( tr( "Alarm Is On" ) ); |
188 | alarmBool = TRUE; | 188 | alarmBool = TRUE; |
189 | snoozeBtn->show(); | 189 | snoozeBtn->show(); |
190 | } | 190 | } |
191 | else | 191 | else |
192 | { | 192 | { |
193 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); | 193 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); |
194 | alarmBool = FALSE; | 194 | alarmBool = FALSE; |
195 | snoozeBtn->hide(); | 195 | snoozeBtn->hide(); |
196 | } | 196 | } |
197 | 197 | ||
198 | QTimer::singleShot( 0, this, SLOT( updateClock() ) ); | 198 | QTimer::singleShot( 0, this, SLOT( updateClock() ) ); |
199 | 199 | ||
200 | Config cfg( "Clock" ); | 200 | Config cfg( "Clock" ); |
201 | cfg.setGroup( "Mode" ); | 201 | cfg.setGroup( "Mode" ); |
202 | int mode = cfg.readBoolEntry( "clockMode"); | 202 | int mode = cfg.readBoolEntry( "clockMode"); |
203 | setSwatchMode( mode); | 203 | setSwatchMode( mode); |
204 | modeSelect( mode); | 204 | modeSelect( mode); |
205 | } | 205 | } |
206 | 206 | ||
207 | Clock::~Clock() | 207 | Clock::~Clock() |
208 | { | 208 | { |
209 | toggleScreenSaver( true ); | 209 | toggleScreenSaver( true ); |
210 | } | 210 | } |
211 | 211 | ||
212 | void Clock::updateClock() | 212 | void Clock::updateClock() |
213 | { | 213 | { |
214 | if ( clockRB->isChecked() ) | 214 | if ( clockRB->isChecked() ) |
215 | { | 215 | { |
216 | QTime tm = QDateTime::currentDateTime().time(); | 216 | QTime tm = QDateTime::currentDateTime().time(); |
217 | QString s; | 217 | QString s; |
218 | if ( ampm ) | 218 | if ( ampm ) |
219 | { | 219 | { |
220 | int hour = tm.hour(); | 220 | int hour = tm.hour(); |
221 | if ( hour == 0 ) | 221 | if ( hour == 0 ) |
222 | hour = 12; | 222 | hour = 12; |
223 | if ( hour > 12 ) | 223 | if ( hour > 12 ) |
224 | hour -= 12; | 224 | hour -= 12; |
225 | s.sprintf( "%2d%c%02d", hour, ':', tm.minute() ); | 225 | s.sprintf( "%2d%c%02d", hour, ':', tm.minute() ); |
226 | ampmLabel->setText( ( tm.hour() >= 12 ) ? "PM" : "AM" ); | 226 | ampmLabel->setText( ( tm.hour() >= 12 ) ? "PM" : "AM" ); |
227 | ampmLabel->show(); | 227 | ampmLabel->show(); |
228 | } | 228 | } |
229 | else | 229 | else |
230 | { | 230 | { |
231 | s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() ); | 231 | s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() ); |
232 | ampmLabel->hide(); | 232 | ampmLabel->hide(); |
233 | } | 233 | } |
234 | lcd->display( s ); | 234 | lcd->display( s ); |
235 | lcd->repaint( FALSE ); | 235 | lcd->repaint( FALSE ); |
236 | aclock->display( QTime::currentTime() ); | 236 | aclock->display( QTime::currentTime() ); |
237 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); | 237 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); |
238 | } | 238 | } |
239 | else | 239 | else |
240 | { | 240 | { |
241 | QTime swatch_time; | 241 | QTime swatch_time; |
242 | QString lcdtext; | 242 | QString lcdtext; |
243 | int totalms = swatch_totalms; | 243 | int totalms = swatch_totalms; |
244 | if ( swatch_running ) | 244 | if ( swatch_running ) |
245 | totalms += swatch_start.elapsed(); | 245 | totalms += swatch_start.elapsed(); |
246 | swatch_time = QTime( 0, 0, 0 ).addMSecs( totalms ); | 246 | swatch_time = QTime( 0, 0, 0 ).addMSecs( totalms ); |
247 | QString d = swatch_running ? QString( " " ) | 247 | QString d = swatch_running ? QString( " " ) |
248 | : QString::number( totalms % 1000 + 1000 ); | 248 | : QString::number( totalms % 1000 + 1000 ); |
249 | lcdtext = swatch_time.toString() + "." + d.right( 3 ).left( sw_prec ); | 249 | lcdtext = swatch_time.toString() + "." + d.right( 3 ).left( sw_prec ); |
250 | lcd->display( lcdtext ); | 250 | lcd->display( lcdtext ); |
251 | lcd->repaint( FALSE ); | 251 | lcd->repaint( FALSE ); |
252 | aclock->display( swatch_time ); | 252 | aclock->display( swatch_time ); |
253 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); | 253 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); |
254 | } | 254 | } |
255 | } | 255 | } |
256 | 256 | ||
257 | void Clock::changeClock( bool a ) | 257 | void Clock::changeClock( bool a ) |
258 | { | 258 | { |
259 | ampm = a; | 259 | ampm = a; |
260 | updateClock(); | 260 | updateClock(); |
261 | } | 261 | } |
262 | 262 | ||
263 | void Clock::clearClock( void ) | 263 | void Clock::clearClock( void ) |
264 | { | 264 | { |
265 | lcd->display( QTime( 0, 0, 0 ).toString() ); | 265 | lcd->display( QTime( 0, 0, 0 ).toString() ); |
266 | aclock->display( QTime( 0, 0, 0 ) ); | 266 | aclock->display( QTime( 0, 0, 0 ) ); |
267 | } | 267 | } |
268 | 268 | ||
269 | void Clock::startSWatch() | 269 | void Clock::startSWatch() |
270 | { | 270 | { |
271 | if(swatch_running) { | 271 | if(swatch_running) { |
272 | stopSWatch(); | 272 | stopSWatch(); |
273 | return; | 273 | return; |
274 | } | 274 | } |
275 | qDebug("startSWatch()"); | 275 | qDebug("startSWatch()"); |
276 | swatch_start.start(); | 276 | swatch_start.start(); |
277 | set->setText( tr( "Stop" ) ); | 277 | set->setText( tr( "Stop" ) ); |
278 | t->start( 1000 ); | 278 | t->start( 1000 ); |
279 | swatch_running = TRUE; | 279 | swatch_running = TRUE; |
280 | // disable screensaver while stop watch is running | 280 | // disable screensaver while stop watch is running |
281 | toggleScreenSaver( FALSE ); | 281 | toggleScreenSaver( FALSE ); |
282 | } | 282 | } |
283 | 283 | ||
284 | void Clock::stopSWatch() | 284 | void Clock::stopSWatch() |
285 | { | 285 | { |
286 | qDebug("stopSWatch()"); | 286 | qDebug("stopSWatch()"); |
287 | swatch_totalms += swatch_start.elapsed(); | 287 | swatch_totalms += swatch_start.elapsed(); |
288 | set->setText( tr( "Start" ) ); | 288 | set->setText( tr( "Start" ) ); |
289 | t->stop(); | 289 | t->stop(); |
290 | swatch_running = FALSE; | 290 | swatch_running = FALSE; |
291 | toggleScreenSaver( TRUE ); | 291 | toggleScreenSaver( TRUE ); |
292 | updateClock(); | 292 | updateClock(); |
293 | } | 293 | } |
294 | 294 | ||
295 | 295 | ||
296 | void Clock::slotSet() | 296 | void Clock::slotSet() |
297 | { | 297 | { |
298 | if ( t->isActive() ) | 298 | if ( t->isActive() ) |
299 | { | 299 | { |
300 | startSWatch(); | 300 | startSWatch(); |
301 | } | 301 | } |
302 | else | 302 | else |
303 | { | 303 | { |
304 | stopSWatch(); | 304 | stopSWatch(); |
305 | } | 305 | } |
306 | } | 306 | } |
307 | 307 | ||
308 | void Clock::slotReset() | 308 | void Clock::slotReset() |
309 | { | 309 | { |
310 | t->stop(); | 310 | t->stop(); |
311 | swatch_start.start(); | 311 | swatch_start.start(); |
312 | swatch_totalms = 0; | 312 | swatch_totalms = 0; |
313 | 313 | ||
314 | if ( swatch_running ) | 314 | if ( swatch_running ) |
315 | t->start( 1000 ); | 315 | t->start( 1000 ); |
316 | 316 | ||
317 | updateClock(); | 317 | updateClock(); |
318 | } | 318 | } |
319 | 319 | ||
320 | void Clock::modeSelect( int m ) | 320 | void Clock::modeSelect( int m ) |
321 | { | 321 | { |
322 | qDebug("Clock::modeSelect( %d) ", m); | 322 | qDebug("Clock::modeSelect( %d) ", m); |
323 | if ( m != 0 ) | 323 | if ( m != 0 ) |
324 | { | 324 | { |
325 | lcd->setNumDigits( 8 + 1 + sw_prec ); | 325 | lcd->setNumDigits( 8 + 1 + sw_prec ); |
326 | lcd->setMinimumWidth( lcd->sizeHint().width() ); | 326 | lcd->setMinimumWidth( lcd->sizeHint().width() ); |
327 | set->setEnabled( TRUE ); | 327 | set->setEnabled( TRUE ); |
328 | reset->setEnabled( TRUE ); | 328 | reset->setEnabled( TRUE ); |
329 | ampmLabel->hide(); | 329 | ampmLabel->hide(); |
330 | 330 | ||
331 | // if(m == 2) { | 331 | // if(m == 2) { |
332 | if ( !swatch_running ) { | 332 | if ( !swatch_running ) { |
333 | t->start( 1000 ); | 333 | t->start( 1000 ); |
334 | } | 334 | } |
335 | // else | 335 | // else |
336 | // { | 336 | // { |
337 | // stopSWatch(); | 337 | // stopSWatch(); |
338 | // } | 338 | // } |
339 | // } | 339 | // } |
340 | } | 340 | } |
341 | else //clock mode | 341 | else //clock mode |
342 | { | 342 | { |
343 | lcd->setNumDigits( 5 ); | 343 | lcd->setNumDigits( 5 ); |
344 | lcd->setMinimumWidth( lcd->sizeHint().width() ); | 344 | lcd->setMinimumWidth( lcd->sizeHint().width() ); |
345 | set->setEnabled( FALSE ); | 345 | set->setEnabled( FALSE ); |
346 | reset->setEnabled( FALSE ); | 346 | reset->setEnabled( FALSE ); |
347 | t->start( 1000 ); | 347 | t->start( 1000 ); |
348 | } | 348 | } |
349 | 349 | ||
350 | Config config( "Clock" ); | 350 | Config config( "Clock" ); |
351 | config.setGroup( "Mode" ); | 351 | config.setGroup( "Mode" ); |
352 | config.writeEntry( "clockMode", m ); | 352 | config.writeEntry( "clockMode", m ); |
353 | updateClock(); | 353 | updateClock(); |
354 | } | 354 | } |
355 | 355 | ||
356 | //this sets the alarm time | 356 | //this sets the alarm time |
357 | void Clock::slotSetAlarm() | 357 | void Clock::slotSetAlarm() |
358 | { | 358 | { |
359 | if ( !snoozeBtn->isHidden() ) | 359 | if ( !snoozeBtn->isHidden() ) |
360 | slotToggleAlarm(); | 360 | slotToggleAlarm(); |
361 | Set_Alarm *setAlarmDlg; | 361 | Set_Alarm *setAlarmDlg; |
362 | setAlarmDlg = new Set_Alarm( this, "SetAlarm", TRUE ); | 362 | setAlarmDlg = new Set_Alarm( this, "SetAlarm", TRUE ); |
363 | int result = setAlarmDlg->exec(); | 363 | int result = setAlarmDlg->exec(); |
364 | if ( result == 1 ) { | 364 | if ( result == 1 ) { |
365 | Config config( "qpe" ); | 365 | Config config( "qpe" ); |
366 | config.setGroup( "Time" ); | 366 | config.setGroup( "Time" ); |
367 | QString tmp; | 367 | QString tmp; |
368 | hour = setAlarmDlg->Hour_Slider->value(); | 368 | hour = setAlarmDlg->Hour_Slider->value(); |
369 | minute = setAlarmDlg->Minute_Slider->value(); | 369 | minute = setAlarmDlg->Minute_Slider->value(); |
370 | snoozeTime = setAlarmDlg->SnoozeSlider->value(); | 370 | snoozeTime = setAlarmDlg->SnoozeSlider->value(); |
371 | if ( ampm ) { | 371 | if ( ampm ) { |
372 | if ( hour == 12 ) | 372 | if ( hour == 12 ) |
373 | hour = 0; | 373 | hour = 0; |
374 | 374 | ||
375 | if ( setAlarmDlg->Pm_RadioButton->isChecked() && hour < 12 ) | 375 | if ( setAlarmDlg->Pm_RadioButton->isChecked() && hour < 12 ) |
376 | hour += 12; | 376 | hour += 12; |
377 | } | 377 | } |
378 | config.writeEntry( "clockAlarmHour", tmp.setNum( hour ), 10 ); | 378 | config.writeEntry( "clockAlarmHour", tmp.setNum( hour ), 10 ); |
379 | config.writeEntry( "clockAlarmMinute", tmp.setNum( minute ), 10 ); | 379 | config.writeEntry( "clockAlarmMinute", tmp.setNum( minute ), 10 ); |
380 | config.writeEntry( "clockAlarmSnooze", tmp.setNum( snoozeTime ), 10 ); | 380 | config.writeEntry( "clockAlarmSnooze", tmp.setNum( snoozeTime ), 10 ); |
381 | config.write(); | 381 | config.write(); |
382 | } | 382 | } |
383 | } | 383 | } |
384 | 384 | ||
385 | void Clock::slotSnooze() | 385 | void Clock::slotSnooze() |
386 | { | 386 | { |
387 | bSound = FALSE; | 387 | bSound = FALSE; |
388 | int warn = 0; | 388 | int warn = 0; |
389 | QTime t = QTime::currentTime(); | 389 | QTime t = QTime::currentTime(); |
390 | QDateTime whenl( when.date(), t.addSecs( snoozeTime * 60 ) ); | 390 | QDateTime whenl( when.date(), t.addSecs( snoozeTime * 60 ) ); |
391 | when = whenl; | 391 | when = whenl; |
392 | AlarmServer::addAlarm( when, | 392 | AlarmServer::addAlarm( when, |
393 | "QPE/Application/clock", | 393 | "QPE/Application/clock", |
394 | "alarm(QDateTime,int)", warn ); | 394 | "alarm(QDateTime,int)", warn ); |
395 | 395 | ||
396 | } | 396 | } |
397 | 397 | ||
398 | //toggles alarm on/off | 398 | //toggles alarm on/off |
399 | void Clock::slotToggleAlarm() | 399 | void Clock::slotToggleAlarm() |
400 | { | 400 | { |
401 | Config config( "qpe" ); | 401 | Config config( "qpe" ); |
402 | config.setGroup( "Time" ); | 402 | config.setGroup( "Time" ); |
403 | if ( alarmBool ) | 403 | if ( alarmBool ) |
404 | { | 404 | { |
405 | config.writeEntry( "clockAlarmSet", "FALSE" ); | 405 | config.writeEntry( "clockAlarmSet", "FALSE" ); |
406 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); | 406 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); |
407 | snoozeBtn->hide(); | 407 | snoozeBtn->hide(); |
408 | alarmBool = FALSE; | 408 | alarmBool = FALSE; |
409 | alarmOff(); | 409 | alarmOff(); |
410 | } | 410 | } |
411 | else | 411 | else |
412 | { | 412 | { |
413 | config.writeEntry( "clockAlarmSet", "TRUE" ); | 413 | config.writeEntry( "clockAlarmSet", "TRUE" ); |
414 | alarmOffBtn->setText( tr( "Alarm Is On" ) ); | 414 | alarmOffBtn->setText( tr( "Alarm Is On" ) ); |
415 | snoozeBtn->show(); | 415 | snoozeBtn->show(); |
416 | alarmBool = TRUE; | 416 | alarmBool = TRUE; |
417 | alarmOn(); | 417 | alarmOn(); |
418 | } | 418 | } |
419 | config.write(); | 419 | config.write(); |
420 | } | 420 | } |
421 | 421 | ||
422 | void Clock::alarmOn() | 422 | void Clock::alarmOn() |
423 | { | 423 | { |
424 | QDate d = QDate::currentDate(); | 424 | QDate d = QDate::currentDate(); |
425 | QTime tm( ( int ) hour, ( int ) minute, 0 ); | 425 | QTime tm( ( int ) hour, ( int ) minute, 0 ); |
426 | qDebug( "Time set " + tm.toString() ); | 426 | qDebug( "Time set " + tm.toString() ); |
427 | QTime t = QTime::currentTime(); | 427 | QTime t = QTime::currentTime(); |
428 | if ( t > tm ) | 428 | if ( t > tm ) |
429 | d = d.addDays( 1 ); | 429 | d = d.addDays( 1 ); |
430 | int warn = 0; | 430 | int warn = 0; |
431 | QDateTime whenl( d, tm ); | 431 | QDateTime whenl( d, tm ); |
432 | when = whenl; | 432 | when = whenl; |
433 | AlarmServer::addAlarm( when, | 433 | AlarmServer::addAlarm( when, |
434 | "QPE/Application/clock", | 434 | "QPE/Application/clock", |
435 | "alarm(QDateTime,int)", warn ); | 435 | "alarm(QDateTime,int)", warn ); |
436 | // setCaption( "Alarm set: " + whenl.toString() ); | 436 | // setCaption( "Alarm set: " + whenl.toString() ); |
437 | setCaption( tr("Alarm set: %1" ).arg(whenl.toString()) ); | 437 | setCaption( tr("Alarm set: %1" ).arg(whenl.toString()) ); |
438 | } | 438 | } |
439 | 439 | ||
440 | void Clock::alarmOff() | 440 | void Clock::alarmOff() |
441 | { | 441 | { |
442 | int warn = 0; | 442 | int warn = 0; |
443 | bSound = FALSE; | 443 | bSound = FALSE; |
444 | AlarmServer::deleteAlarm( when, | 444 | AlarmServer::deleteAlarm( when, |
445 | "QPE/Application/clock", | 445 | "QPE/Application/clock", |
446 | "alarm(QDateTime,int)", warn ); | 446 | "alarm(QDateTime,int)", warn ); |
447 | qDebug( "Alarm Off " + when.toString() ); | 447 | qDebug( "Alarm Off " + when.toString() ); |
448 | setCaption( tr("Clock") ); | 448 | setCaption( tr("Clock") ); |
449 | } | 449 | } |
450 | 450 | ||
451 | void Clock::clearTimer() | 451 | void Clock::clearTimer() |
452 | { | 452 | { |
453 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); | 453 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); |
454 | alarmBool = FALSE; | 454 | alarmBool = FALSE; |
455 | snoozeBtn->hide(); | 455 | snoozeBtn->hide(); |
456 | setCaption( tr("Clock") ); | 456 | setCaption( tr("Clock") ); |
457 | } | 457 | } |
458 | 458 | ||
459 | void Clock::appMessage( const QCString& msg, const QByteArray& /*data*/ ) | 459 | void Clock::appMessage( const QCString& msg, const QByteArray& /*data*/ ) |
460 | { | 460 | { |
461 | int stopTimer = 0; | 461 | int stopTimer = 0; |
462 | int timerStay = 5000; | 462 | int timerStay = 5000; |
463 | bSound = TRUE; | 463 | bSound = TRUE; |
464 | qDebug( "Message received in clock" ); | 464 | qDebug( "Message received in clock" ); |
465 | if ( msg == "alarm(QDateTime,int)" ) | 465 | if ( msg == "alarm(QDateTime,int)" ) |
466 | { | 466 | { |
467 | Config config( "qpe" ); | 467 | Config config( "qpe" ); |
468 | config.setGroup( "Time" ); | 468 | config.setGroup( "Time" ); |
469 | if ( config.readBoolEntry( "mp3Alarm", 0 ) ) | 469 | if ( config.readBoolEntry( "mp3Alarm", 0 ) ) |
470 | { | 470 | { |
471 | clearTimer(); | 471 | clearTimer(); |
472 | pthread_t thread; | 472 | pthread_t thread; |
473 | pthread_create(&thread, NULL, (void * (*) (void *))startPlayer, NULL/* &*/); | 473 | pthread_create(&thread, NULL, (void * (*) (void *))startPlayer, NULL/* &*/); |
474 | 474 | ||
475 | } | 475 | } |
476 | else | 476 | else |
477 | { | 477 | { |
478 | 478 | ||
479 | Sound::soundAlarm(); | 479 | Sound::soundAlarm(); |
480 | stopTimer = startTimer( timerStay ); | 480 | stopTimer = startTimer( timerStay ); |
481 | } | 481 | } |
482 | } | 482 | } |
483 | 483 | ||
484 | if ( msg == "timerStart()" ) | 484 | if ( msg == "timerStart()" ) |
485 | { | 485 | { |
486 | slotStartTimer(); | 486 | slotStartTimer(); |
487 | } | 487 | } |
488 | if ( msg == "timerStop()" ) | 488 | if ( msg == "timerStop()" ) |
489 | { | 489 | { |
490 | slotStopTimer(); | 490 | slotStopTimer(); |
491 | } | 491 | } |
492 | if ( msg == "timerReset()" ) | 492 | if ( msg == "timerReset()" ) |
493 | { | 493 | { |
494 | slotResetTimer(); | 494 | slotResetTimer(); |
495 | } | 495 | } |
496 | 496 | ||
497 | show(); | 497 | show(); |
498 | raise(); | 498 | raise(); |
499 | QPEApplication::setKeepRunning(); | 499 | QPEApplication::setKeepRunning(); |
500 | setActiveWindow(); | 500 | setActiveWindow(); |
501 | } | 501 | } |
502 | 502 | ||
503 | void Clock::timerEvent( QTimerEvent *e ) | 503 | void Clock::timerEvent( QTimerEvent *e ) |
504 | { | 504 | { |
505 | static int stop = 0; | 505 | static int stop = 0; |
506 | if ( stop < 120 && bSound ) | 506 | if ( stop < 120 && bSound ) |
507 | { | 507 | { |
508 | Sound::soundAlarm(); | 508 | Sound::soundAlarm(); |
509 | stop++; | 509 | stop++; |
510 | } | 510 | } |
511 | else | 511 | else |
512 | { | 512 | { |
513 | stop = 0; | 513 | stop = 0; |
514 | killTimer( e->timerId() ); | 514 | killTimer( e->timerId() ); |
515 | clearTimer(); | 515 | clearTimer(); |
516 | setCaption( tr( "Clock: Alarm was missed." ) ); | 516 | setCaption( tr( "Clock: Alarm was missed." ) ); |
517 | } | 517 | } |
518 | } | 518 | } |
519 | 519 | ||
520 | AnalogClock::AnalogClock(QWidget * parent, const char * name) : QFrame( parent, name ), clear(true) | 520 | AnalogClock::AnalogClock(QWidget * parent, const char * name) : QFrame( parent, name ), clear(true) |
521 | { | 521 | { |
522 | QWidget *d = QApplication::desktop(); | 522 | QWidget *d = QApplication::desktop(); |
523 | if(d->width() <= 240) | 523 | if(d->width() <= 240) |
524 | bg = Resource::loadPixmap("clock/bg"); | 524 | bg = Resource::loadPixmap("clock/bg"); |
525 | } | 525 | } |
526 | 526 | ||
527 | QSizePolicy AnalogClock::sizePolicy() const | 527 | QSizePolicy AnalogClock::sizePolicy() const |
528 | { | 528 | { |
529 | return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); | 529 | return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); |
530 | } | 530 | } |
531 | 531 | ||
532 | void AnalogClock::drawContents( QPainter *p ) | 532 | void AnalogClock::drawContents( QPainter *p ) |
533 | { | 533 | { |
534 | QRect r = contentsRect(); | 534 | QRect r = contentsRect(); |
535 | QRect fr; | 535 | QRect fr; |
536 | 536 | ||
537 | p->drawPixmap(QPoint(0, 0), bg, r); | 537 | p->drawPixmap(QPoint(0, 0), bg, r); |
538 | 538 | ||
539 | if ( r. width ( ) > r. height ( )) | 539 | if ( r. width ( ) > r. height ( )) |
540 | fr. setRect (( r. width ( ) - r. height ( )) / 2, r. y ( ), r. height ( ), r. height ( )); | 540 | fr. setRect (( r. width ( ) - r. height ( )) / 2, r. y ( ), r. height ( ), r. height ( )); |
541 | else | 541 | else |
542 | fr. setRect ( r. x ( ), ( r. height ( ) - r. width ( )) / 2, r. width ( ), r. width ( )); | 542 | fr. setRect ( r. x ( ), ( r. height ( ) - r. width ( )) / 2, r. width ( ), r. width ( )); |
543 | 543 | ||
544 | QPoint center = fr. center ( ); // ( fr.x() + fr.width() / 2, fr.y() + fr.height() / 2 ); | 544 | QPoint center = fr. center ( ); // ( fr.x() + fr.width() / 2, fr.y() + fr.height() / 2 ); |
545 | QPoint l1 ( center. x ( ), fr. y ( ) + 2 ); | 545 | QPoint l1 ( center. x ( ), fr. y ( ) + 2 ); |
546 | QPoint l2 ( center. x ( ), fr. y ( ) + 8 ); | 546 | QPoint l2 ( center. x ( ), fr. y ( ) + 8 ); |
547 | 547 | ||
548 | 548 | ||
549 | 549 | ||
550 | if ( clear ) | 550 | if ( clear ) |
551 | { | 551 | { |
552 | erase ( r ); | 552 | erase ( r ); |
553 | p-> setPen ( NoPen ); | 553 | p-> setPen ( NoPen ); |
554 | p-> setBrush ( colorGroup ( ). color ( QColorGroup::Base )); | 554 | p-> setBrush ( colorGroup ( ). color ( QColorGroup::Base )); |
555 | p-> drawEllipse ( fr ); | 555 | p-> drawEllipse ( fr ); |
556 | p-> setBrush ( NoBrush ); | 556 | p-> setBrush ( NoBrush ); |
557 | 557 | ||
558 | // draw ticks | 558 | // draw ticks |
559 | p->setPen( QPen( colorGroup ( ). color ( QColorGroup::Text ), 1 ) ); | 559 | p->setPen( QPen( colorGroup ( ). color ( QColorGroup::Text ), 1 ) ); |
560 | for ( int i = 0; i < 12; i++ ) | 560 | for ( int i = 0; i < 12; i++ ) |
561 | p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) ); | 561 | p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) ); |
562 | } | 562 | } |
563 | else | 563 | else |
564 | { | 564 | { |
565 | drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Base ), prevTime, &currTime ); | 565 | drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Base ), prevTime, &currTime ); |
566 | } | 566 | } |
567 | 567 | ||
568 | drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Text ), currTime ); | 568 | drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Text ), currTime ); |
569 | 569 | ||
570 | prevTime = currTime; | 570 | prevTime = currTime; |
571 | } | 571 | } |
572 | 572 | ||
573 | void AnalogClock::drawPointers ( QPainter *p, const QRect &r, const QColor &c, const QTime &t, const QTime *t2 ) | 573 | void AnalogClock::drawPointers ( QPainter *p, const QRect &r, const QColor &c, const QTime &t, const QTime *t2 ) |
574 | { | 574 | { |
575 | QPoint center = r. center ( ); | 575 | QPoint center = r. center ( ); |
576 | 576 | ||
577 | QPoint h1( center. x ( ), r. y ( ) + r. height ( ) / 4 ); | 577 | QPoint h1( center. x ( ), r. y ( ) + r. height ( ) / 4 ); |
578 | QPoint h2( center. x ( ), center. y ( ) ); | 578 | QPoint h2( center. x ( ), center. y ( ) ); |
579 | 579 | ||
580 | QPoint m1( center. x ( ), r.y() + r.height() / 8 ); | 580 | QPoint m1( center. x ( ), r.y() + r.height() / 8 ); |
581 | QPoint m2( center. x ( ), center. y ( ) ); | 581 | QPoint m2( center. x ( ), center. y ( ) ); |
582 | 582 | ||
583 | QPoint s1( center. x ( ), r. y ( ) + 8 ); | 583 | QPoint s1( center. x ( ), r. y ( ) + 8 ); |
584 | QPoint s2( center. x ( ), center. y ( ) ); | 584 | QPoint s2( center. x ( ), center. y ( ) ); |
585 | 585 | ||
586 | 586 | ||
587 | if ( !t2 || ( t. minute ( ) != t2-> minute ( ) || t. hour ( ) != t2-> hour ( ))) { | 587 | if ( !t2 || ( t. minute ( ) != t2-> minute ( ) || t. hour ( ) != t2-> hour ( ))) { |
588 | // draw hour pointer | 588 | // draw hour pointer |
589 | h1 = rotate( center, h1, 30 * ( t.hour() % 12 ) + t.minute() / 2 ); | 589 | h1 = rotate( center, h1, 30 * ( t.hour() % 12 ) + t.minute() / 2 ); |
590 | h2 = rotate( center, h2, 30 * ( t.hour() % 12 ) + t.minute() / 2 ); | 590 | h2 = rotate( center, h2, 30 * ( t.hour() % 12 ) + t.minute() / 2 ); |
591 | p-> setPen ( QPen ( c, 3 )); | 591 | p-> setPen ( QPen ( c, 3 )); |
592 | p-> drawLine ( h1, h2 ); | 592 | p-> drawLine ( h1, h2 ); |
593 | } | 593 | } |
594 | 594 | ||
595 | if ( !t2 || ( t. minute ( ) != t2-> minute ( ))) { | 595 | if ( !t2 || ( t. minute ( ) != t2-> minute ( ))) { |
596 | // draw minute pointer | 596 | // draw minute pointer |
597 | m1 = rotate( center, m1, t.minute() * 6 ); | 597 | m1 = rotate( center, m1, t.minute() * 6 ); |
598 | m2 = rotate( center, m2, t.minute() * 6 ); | 598 | m2 = rotate( center, m2, t.minute() * 6 ); |
599 | p-> setPen ( QPen ( c, 2 )); | 599 | p-> setPen ( QPen ( c, 2 )); |
600 | p-> drawLine ( m1, m2 ); | 600 | p-> drawLine ( m1, m2 ); |
601 | } | 601 | } |
602 | 602 | ||
603 | if ( !t2 || ( t. second ( ) != t2-> second ( ))) { | 603 | if ( !t2 || ( t. second ( ) != t2-> second ( ))) { |
604 | // draw second pointer | 604 | // draw second pointer |
605 | s1 = rotate( center, s1, t.second() * 6 ); | 605 | s1 = rotate( center, s1, t.second() * 6 ); |
606 | s2 = rotate( center, s2, t.second() * 6 ); | 606 | s2 = rotate( center, s2, t.second() * 6 ); |
607 | p-> setPen ( QPen ( c, 1 )); | 607 | p-> setPen ( QPen ( c, 1 )); |
608 | p-> drawLine ( s1, s2 ); | 608 | p-> drawLine ( s1, s2 ); |
609 | } | 609 | } |
610 | } | 610 | } |
611 | 611 | ||
612 | void AnalogClock::display( const QTime& t ) | 612 | void AnalogClock::display( const QTime& t ) |
613 | { | 613 | { |
614 | currTime = t; | 614 | currTime = t; |
615 | clear = false; | 615 | clear = false; |
616 | repaint( false ); | 616 | repaint( false ); |
617 | clear = true; | 617 | clear = true; |
618 | } | 618 | } |
619 | 619 | ||
620 | QPoint AnalogClock::rotate( QPoint c, QPoint p, int a ) | 620 | QPoint AnalogClock::rotate( QPoint c, QPoint p, int a ) |
621 | { | 621 | { |
622 | double angle = deg2rad * ( - a + 180 ); | 622 | double angle = deg2rad * ( - a + 180 ); |
623 | double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) - | 623 | double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) - |
624 | ( p.y() - c.y() ) * sin( angle ); | 624 | ( p.y() - c.y() ) * sin( angle ); |
625 | double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) + | 625 | double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) + |
626 | ( p.x() - c.x() ) * sin( angle ); | 626 | ( p.x() - c.x() ) * sin( angle ); |
627 | return QPoint( nx, ny ); | 627 | return QPoint( nx, ny ); |
628 | } | 628 | } |
629 | 629 | ||
630 | void Clock::slotAdjustTime() | 630 | void Clock::slotAdjustTime() |
631 | { | 631 | { |
632 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 632 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
633 | e << QString( "systemtime" ); | 633 | e << QString( "systemtime" ); |
634 | } | 634 | } |
635 | 635 | ||
636 | void Clock::slotStartTimer() | 636 | void Clock::slotStartTimer() |
637 | { | 637 | { |
638 | if ( clockRB->isChecked() ) | 638 | if ( clockRB->isChecked() ) |
639 | setSwatchMode( 1); | 639 | setSwatchMode( 1); |
640 | startSWatch(); | 640 | startSWatch(); |
641 | } | 641 | } |
642 | 642 | ||
643 | void Clock::slotStopTimer() | 643 | void Clock::slotStopTimer() |
644 | { | 644 | { |
645 | if ( clockRB->isChecked() ) | 645 | if ( clockRB->isChecked() ) |
646 | setSwatchMode( 1); | 646 | setSwatchMode( 1); |
647 | stopSWatch(); | 647 | stopSWatch(); |
648 | } | 648 | } |
649 | 649 | ||
650 | void Clock::slotResetTimer() | 650 | void Clock::slotResetTimer() |
651 | { | 651 | { |
652 | if ( clockRB->isChecked() ) | 652 | if ( clockRB->isChecked() ) |
653 | setSwatchMode( 1); | 653 | setSwatchMode( 1); |
654 | slotReset(); | 654 | slotReset(); |
655 | } | 655 | } |
656 | 656 | ||
657 | void Clock::setSwatchMode(int mode) | 657 | void Clock::setSwatchMode(int mode) |
658 | { | 658 | { |
659 | qDebug("Clock::setSwatchMode( %d)", mode); | 659 | qDebug("Clock::setSwatchMode( %d)", mode); |
660 | swatchRB->setChecked( mode); | 660 | swatchRB->setChecked( mode); |
661 | clearClock( ); | 661 | clearClock( ); |
662 | modeSelect( mode ); | 662 | modeSelect( mode ); |
663 | } | 663 | } |