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