summaryrefslogtreecommitdiff
path: root/core/settings/citytime
Unidiff
Diffstat (limited to 'core/settings/citytime') (more/less context) (ignore whitespace changes)
-rw-r--r--core/settings/citytime/citytime.cpp94
-rw-r--r--core/settings/citytime/citytimebase.cpp120
-rw-r--r--core/settings/citytime/zonemap.cpp402
3 files changed, 314 insertions, 302 deletions
diff --git a/core/settings/citytime/citytime.cpp b/core/settings/citytime/citytime.cpp
index 721285d..d73bda1 100644
--- a/core/settings/citytime/citytime.cpp
+++ b/core/settings/citytime/citytime.cpp
@@ -14,48 +14,52 @@
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 20
21// changes by Maximilian Reiss <harlekin@handhelds.org> 21// changes by Maximilian Reiss <harlekin@handhelds.org>
22 22
23#include "zonemap.h" 23#include "zonemap.h"
24#include "citytime.h" 24#include "citytime.h"
25 25
26/* OPIE */
26#include <qpe/qpeapplication.h> 27#include <qpe/qpeapplication.h>
27#include <qpe/config.h> 28#include <qpe/config.h>
28#include <qpe/tzselect.h> 29#include <qpe/tzselect.h>
29#if !defined(QT_NO_COP) 30#if !defined(QT_NO_COP)
30#include <qpe/qcopenvelope_qws.h> 31#include <qpe/qcopenvelope_qws.h>
31#endif 32#endif
33#include <opie2/odebug.h>
32 34
35/* QT */
33#include <qlabel.h> 36#include <qlabel.h>
34#include <qmessagebox.h> 37#include <qmessagebox.h>
35#include <qtoolbutton.h> 38#include <qtoolbutton.h>
36#include <qlayout.h> 39#include <qlayout.h>
37 40
41/* STD */
38#include <stdlib.h> 42#include <stdlib.h>
39 43
40CityTime::CityTime( QWidget *parent, const char* name, 44CityTime::CityTime( QWidget *parent, const char* name,
41 WFlags fl ) 45 WFlags fl )
42 : CityTimeBase( parent, name, fl ), 46 : CityTimeBase( parent, name, fl ),
43 strRealTz(0), 47 strRealTz(0),
44 bAdded(false) 48 bAdded(false)
45{ 49{
46 Config config( "qpe" ); 50 Config config( "qpe" );
47 config.setGroup( "Time" ); 51 config.setGroup( "Time" );
48 bWhichClock = config.readBoolEntry( "AMPM", TRUE ); 52 bWhichClock = config.readBoolEntry( "AMPM", TRUE );
49 qDebug( QString("%1").arg(bWhichClock) ); 53 odebug << QString("%1").arg(bWhichClock) << oendl;
50 frmMap->changeClock( bWhichClock ); 54 frmMap->changeClock( bWhichClock );
51 55
52 char *pEnv; 56 char *pEnv;
53 pEnv = NULL; 57 pEnv = NULL;
54 pEnv = getenv("TZ"); 58 pEnv = getenv("TZ");
55 if ( pEnv ) 59 if ( pEnv )
56 strRealTz = pEnv; 60 strRealTz = pEnv;
57 pEnv = NULL; 61 pEnv = NULL;
58 pEnv = getenv("HOME"); 62 pEnv = getenv("HOME");
59 if ( pEnv ) 63 if ( pEnv )
60 strHome = pEnv; 64 strHome = pEnv;
61 // append the labels to their respective lists... 65 // append the labels to their respective lists...
@@ -109,87 +113,87 @@ CityTime::CityTime( QWidget *parent, const char* name,
109 bAdded = true; 113 bAdded = true;
110 readInTimes(); 114 readInTimes();
111 changed = FALSE; 115 changed = FALSE;
112 QObject::connect( qApp, SIGNAL( clockChanged(bool) ), 116 QObject::connect( qApp, SIGNAL( clockChanged(bool) ),
113 this, SLOT( changeClock(bool) ) ); 117 this, SLOT( changeClock(bool) ) );
114 // now start the timer so we can update the time quickly every second 118 // now start the timer so we can update the time quickly every second
115 timerEvent( 0 ); 119 timerEvent( 0 );
116} 120}
117 121
118CityTime::~CityTime() 122CityTime::~CityTime()
119{ 123{
120 if ( changed ) { 124 if ( changed ) {
121 Config cfg("CityTime"); 125 Config cfg("CityTime");
122 cfg.setGroup("TimeZones"); 126 cfg.setGroup("TimeZones");
123 QListIterator<QToolButton> itCity( listCities ); 127 QListIterator<QToolButton> itCity( listCities );
124 int i; 128 int i;
125 bool realTzWritten = FALSE; 129 bool realTzWritten = FALSE;
126 for ( i = 0, itCity.toFirst(); i < CITIES; i++, ++itCity ) { 130 for ( i = 0, itCity.toFirst(); i < CITIES; i++, ++itCity ) {
127 if ( !strCityTz[i].isNull() ) { 131 if ( !strCityTz[i].isNull() ) {
128 cfg.writeEntry("Zone"+QString::number(i), strCityTz[i]); 132 cfg.writeEntry("Zone"+QString::number(i), strCityTz[i]);
129 cfg.writeEntry("ZoneName"+QString::number(i), itCity.current()->text()); 133 cfg.writeEntry("ZoneName"+QString::number(i), itCity.current()->text());
130 if ( strCityTz[i] == strRealTz ) 134 if ( strCityTz[i] == strRealTz )
131 realTzWritten = TRUE; 135 realTzWritten = TRUE;
132 } 136 }
133 } 137 }
134 if ( realTzWritten ) { 138 if ( realTzWritten ) {
135 cfg.removeEntry("Zone"+QString::number(CITIES)); 139 cfg.removeEntry("Zone"+QString::number(CITIES));
136 cfg.removeEntry("ZoneName"+QString::number(CITIES)); 140 cfg.removeEntry("ZoneName"+QString::number(CITIES));
137 } else { 141 } else {
138 cfg.writeEntry("Zone"+QString::number(CITIES), strRealTz); 142 cfg.writeEntry("Zone"+QString::number(CITIES), strRealTz);
139 if ( nameRealTz.isEmpty() ) { 143 if ( nameRealTz.isEmpty() ) {
140 int i = strRealTz.find( '/' ); 144 int i = strRealTz.find( '/' );
141 nameRealTz = strRealTz.mid( i+1 ); 145 nameRealTz = strRealTz.mid( i+1 );
142 } 146 }
143 cfg.writeEntry("ZoneName"+QString::number(CITIES), nameRealTz); 147 cfg.writeEntry("ZoneName"+QString::number(CITIES), nameRealTz);
144 } 148 }
145 QCopEnvelope ( "QPE/System", "timeZoneListChange()" ); 149 QCopEnvelope ( "QPE/System", "timeZoneListChange()" );
146 150
147 changed = FALSE; 151 changed = FALSE;
148 } 152 }
149 // restore the timezone, just in case we messed with it and 153 // restore the timezone, just in case we messed with it and
150 // are destroyed at an inoppurtune moment 154 // are destroyed at an inoppurtune moment
151 if ( !strRealTz.isNull() ) { 155 if ( !strRealTz.isNull() ) {
152 // this should be checked, but there is not much that can done at this 156 // this should be checked, but there is not much that can done at this
153 //point if it fails 157 //point if it fails
154 setenv( "TZ", strRealTz, true ); 158 setenv( "TZ", strRealTz, true );
155 } 159 }
156} 160}
157 161
158void CityTime::timerEvent( QTimerEvent *e ) 162void CityTime::timerEvent( QTimerEvent *e )
159{ 163{
160 if ( e ) 164 if ( e )
161 killTimer( timerId ); 165 killTimer( timerId );
162 // change the time again!! 166 // change the time again!!
163 showTime(); 167 showTime();
164 int ms = 1000 - QTime::currentTime().msec(); 168 int ms = 1000 - QTime::currentTime().msec();
165 timerId = startTimer( ms ); 169 timerId = startTimer( ms );
166} 170}
167 171
168void CityTime::mousePressEvent( QMouseEvent * ) 172void CityTime::mousePressEvent( QMouseEvent * )
169{ 173{
170 // DEBUG enable this to get a look at the zone information DEBUG 174 // DEBUG enable this to get a look at the zone information DEBUG
171// frmMap->showZones(); 175// frmMap->showZones();
172} 176}
173 177
174void CityTime::showTime( void ) 178void CityTime::showTime( void )
175{ 179{
176 int i; 180 int i;
177 QListIterator<QLabel> itTime(listTimes); 181 QListIterator<QLabel> itTime(listTimes);
178 182
179 // traverse the list... 183 // traverse the list...
180 for ( i = 0, itTime.toFirst(); i < CITIES; i++, ++itTime) { 184 for ( i = 0, itTime.toFirst(); i < CITIES; i++, ++itTime) {
181 if ( !strCityTz[i].isNull() ) { 185 if ( !strCityTz[i].isNull() ) {
182 if ( setenv( "TZ", strCityTz[i], true ) == 0 ) { 186 if ( setenv( "TZ", strCityTz[i], true ) == 0 ) {
183 itTime.current()->setText( TimeString::shortTime( bWhichClock ) ); 187 itTime.current()->setText( TimeString::shortTime( bWhichClock ) );
184 } else { 188 } else {
185 QMessageBox::critical( this, tr( "Time Changing" ), 189 QMessageBox::critical( this, tr( "Time Changing" ),
186 tr( "There was a problem setting timezone %1" ) 190 tr( "There was a problem setting timezone %1" )
187 .arg( QString::number( i + 1 ) ) ); 191 .arg( QString::number( i + 1 ) ) );
188 } 192 }
189 } 193 }
190 } 194 }
191 // done playing around... put it all back 195 // done playing around... put it all back
192 unsetenv( "TZ" ); 196 unsetenv( "TZ" );
193 if ( !strRealTz.isNull() ) { 197 if ( !strRealTz.isNull() ) {
194 if ( setenv( "TZ", strRealTz, true ) != 0 ) { 198 if ( setenv( "TZ", strRealTz, true ) != 0 ) {
195 QMessageBox::critical( this, tr( "Restore Time Zone" ), 199 QMessageBox::critical( this, tr( "Restore Time Zone" ),
@@ -214,66 +218,66 @@ void CityTime::slotNewTz( const QString & strNewCountry,
214 QListIterator<QToolButton> itCity(listCities); 218 QListIterator<QToolButton> itCity(listCities);
215 int i; 219 int i;
216 // go through the list and make adjustments based on which button is on 220 // go through the list and make adjustments based on which button is on
217 for ( i = 0, itCity.toFirst(); itCity.current(), i < CITIES; i++, ++itCity ) { 221 for ( i = 0, itCity.toFirst(); itCity.current(), i < CITIES; i++, ++itCity ) {
218 QToolButton *cmdTmp = itCity.current(); 222 QToolButton *cmdTmp = itCity.current();
219 if ( cmdTmp->isOn() ) { 223 if ( cmdTmp->isOn() ) {
220 strCityTz[i] = strNewCountry + strNewCity; 224 strCityTz[i] = strNewCountry + strNewCity;
221 QString s = strNewCity; 225 QString s = strNewCity;
222 cmdTmp->setText( s.replace( QRegExp("_"), " " ) ); 226 cmdTmp->setText( s.replace( QRegExp("_"), " " ) );
223 cmdTmp->toggle(); 227 cmdTmp->toggle();
224 // we can actually break, since there is only one button 228 // we can actually break, since there is only one button
225 // that is ever pressed! 229 // that is ever pressed!
226 changed = TRUE; 230 changed = TRUE;
227 break; 231 break;
228 } 232 }
229 } 233 }
230 showTime(); 234 showTime();
231 buttonWidget->show(); 235 buttonWidget->show();
232 selWidget->hide(); 236 selWidget->hide();
233} 237}
234 238
235void CityTime::readInTimes( void ) 239void CityTime::readInTimes( void )
236{ 240{
237 Config cfg("CityTime"); 241 Config cfg("CityTime");
238 cfg.setGroup("TimeZones"); 242 cfg.setGroup("TimeZones");
239 QListIterator<QToolButton> itCity( listCities ); 243 QListIterator<QToolButton> itCity( listCities );
240 int i=0; 244 int i=0;
241 nameRealTz = QString::null; 245 nameRealTz = QString::null;
242 QString zn; 246 QString zn;
243 for ( ; i < CITIES ; i++ ) { 247 for ( ; i < CITIES ; i++ ) {
244 zn = cfg.readEntry("Zone"+QString::number(i), QString::null); 248 zn = cfg.readEntry("Zone"+QString::number(i), QString::null);
245 if ( zn.isNull() ) 249 if ( zn.isNull() )
246 break; 250 break;
247 QString nm = cfg.readEntry("ZoneName"+QString::number(i)); 251 QString nm = cfg.readEntry("ZoneName"+QString::number(i));
248 strCityTz[i] = zn; 252 strCityTz[i] = zn;
249 itCity.current()->setText(nm); 253 itCity.current()->setText(nm);
250 if ( zn == strRealTz ) 254 if ( zn == strRealTz )
251 nameRealTz = nm; 255 nameRealTz = nm;
252 ++itCity; 256 ++itCity;
253 } 257 }
254 if ( i == 0 ) { 258 if ( i == 0 ) {
255 // write in our own in a shameless self promotion and some humor 259 // write in our own in a shameless self promotion and some humor
256 QStringList list = timezoneDefaults(); 260 QStringList list = timezoneDefaults();
257 int i; 261 int i;
258 QStringList::Iterator it = list.begin(); 262 QStringList::Iterator it = list.begin();
259 for ( i = 0, itCity.toFirst(); i < CITIES && itCity.current(); 263 for ( i = 0, itCity.toFirst(); i < CITIES && itCity.current();
260 i++, ++itCity ) { 264 i++, ++itCity ) {
261 strCityTz[i] = *it++; 265 strCityTz[i] = *it++;
262 itCity.current()->setText( *it++ ); 266 itCity.current()->setText( *it++ );
263 } 267 }
264 } 268 }
265 if ( nameRealTz.isEmpty() ) { 269 if ( nameRealTz.isEmpty() ) {
266 //remember the current time zone even if we don't have room 270 //remember the current time zone even if we don't have room
267 //to show it. 271 //to show it.
268 zn = cfg.readEntry("Zone"+QString::number(CITIES), QString::null); 272 zn = cfg.readEntry("Zone"+QString::number(CITIES), QString::null);
269 if ( zn == strRealTz ) 273 if ( zn == strRealTz )
270 nameRealTz = cfg.readEntry("ZoneName"+QString::number(CITIES)); 274 nameRealTz = cfg.readEntry("ZoneName"+QString::number(CITIES));
271 i++; 275 i++;
272 } 276 }
273} 277}
274 278
275void CityTime::changeClock( bool newClock ) 279void CityTime::changeClock( bool newClock )
276{ 280{
277 bWhichClock = newClock; 281 bWhichClock = newClock;
278 showTime(); 282 showTime();
279} 283}
diff --git a/core/settings/citytime/citytimebase.cpp b/core/settings/citytime/citytimebase.cpp
index 323929b..77cb91d 100644
--- a/core/settings/citytime/citytimebase.cpp
+++ b/core/settings/citytime/citytimebase.cpp
@@ -1,34 +1,38 @@
1 1
2 2
3// changes by Maximilian Reiss <harlekin@handhelds.org> 3// changes by Maximilian Reiss <harlekin@handhelds.org>
4 4
5#include "citytimebase.h" 5#include "citytimebase.h"
6#include "zonemap.h"
7
8/* OPIE */
9#include <opie2/odebug.h>
6 10
11/* QT */
7#include <qlabel.h> 12#include <qlabel.h>
8#include <qtoolbutton.h> 13#include <qtoolbutton.h>
9#include "zonemap.h"
10#include <qlayout.h> 14#include <qlayout.h>
11#include <qwhatsthis.h> 15#include <qwhatsthis.h>
12 16
13 17
14/* 18/*
15 * Constructs a CityTimeBase which is a child of 'parent', with the 19 * Constructs a CityTimeBase which is a child of 'parent', with the
16 * name 'name' and widget flags set to 'f' 20 * name 'name' and widget flags set to 'f'
17 */ 21 */
18CityTimeBase::CityTimeBase( QWidget* parent, const char* name, WFlags ) 22CityTimeBase::CityTimeBase( QWidget* parent, const char* name, WFlags )
19 : QWidget( parent, name, WStyle_ContextHelp ) 23 : QWidget( parent, name, WStyle_ContextHelp )
20{ 24{
21 if ( !name ) 25 if ( !name )
22 setName( "CityTimeBase" ); 26 setName( "CityTimeBase" );
23 setCaption( tr( "City Time" ) ); 27 setCaption( tr( "City Time" ) );
24 CityTimeBaseLayout = new QVBoxLayout( this ); 28 CityTimeBaseLayout = new QVBoxLayout( this );
25 CityTimeBaseLayout->setSpacing( 3 ); 29 CityTimeBaseLayout->setSpacing( 3 );
26 CityTimeBaseLayout->setMargin( 0 ); 30 CityTimeBaseLayout->setMargin( 0 );
27 31
28 frmMap = new ZoneMap( this, "frmMap" ); 32 frmMap = new ZoneMap( this, "frmMap" );
29 frmMap->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)7, frmMap->sizePolicy().hasHeightForWidth() ) ); 33 frmMap->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)7, frmMap->sizePolicy().hasHeightForWidth() ) );
30 CityTimeBaseLayout->addWidget( frmMap ); 34 CityTimeBaseLayout->addWidget( frmMap );
31 35
32 buttonWidget = new QWidget( this ); 36 buttonWidget = new QWidget( this );
33 QWhatsThis::add( buttonWidget, tr( "Click on one of the set cities to replace it" ) ); 37 QWhatsThis::add( buttonWidget, tr( "Click on one of the set cities to replace it" ) );
34 Layout2 = new QGridLayout( buttonWidget ); 38 Layout2 = new QGridLayout( buttonWidget );
@@ -332,80 +336,80 @@ CityTimeBase::~CityTimeBase()
332{ 336{
333 // no need to delete child widgets, Qt does it all for us 337 // no need to delete child widgets, Qt does it all for us
334} 338}
335 339
336/* 340/*
337 * Main event handler. Reimplemented to handle application 341 * Main event handler. Reimplemented to handle application
338 * font changes 342 * font changes
339 */ 343 */
340bool CityTimeBase::event( QEvent* ev ) 344bool CityTimeBase::event( QEvent* ev )
341{ 345{
342 bool ret = QWidget::event( ev ); 346 bool ret = QWidget::event( ev );
343 if ( ev->type() == QEvent::ApplicationFontChange ) { 347 if ( ev->type() == QEvent::ApplicationFontChange ) {
344 QFont cmdCity7_font( cmdCity7->font() ); 348 QFont cmdCity7_font( cmdCity7->font() );
345 cmdCity7_font.setBold( TRUE ); 349 cmdCity7_font.setBold( TRUE );
346 cmdCity7->setFont( cmdCity7_font ); 350 cmdCity7->setFont( cmdCity7_font );
347 QFont lblCTime9_font( lblCTime9->font() ); 351 QFont lblCTime9_font( lblCTime9->font() );
348 lblCTime9_font.setPointSize( 10 ); 352 lblCTime9_font.setPointSize( 10 );
349 lblCTime9->setFont( lblCTime9_font ); 353 lblCTime9->setFont( lblCTime9_font );
350 QFont cmdCity8_font( cmdCity8->font() ); 354 QFont cmdCity8_font( cmdCity8->font() );
351 cmdCity8_font.setBold( TRUE ); 355 cmdCity8_font.setBold( TRUE );
352 cmdCity8->setFont( cmdCity8_font ); 356 cmdCity8->setFont( cmdCity8_font );
353 QFont cmdCity2_font( cmdCity2->font() ); 357 QFont cmdCity2_font( cmdCity2->font() );
354 cmdCity2_font.setBold( TRUE ); 358 cmdCity2_font.setBold( TRUE );
355 cmdCity2->setFont( cmdCity2_font ); 359 cmdCity2->setFont( cmdCity2_font );
356 QFont lblCTime6_font( lblCTime6->font() ); 360 QFont lblCTime6_font( lblCTime6->font() );
357 lblCTime6_font.setPointSize( 10 ); 361 lblCTime6_font.setPointSize( 10 );
358 lblCTime6->setFont( lblCTime6_font ); 362 lblCTime6->setFont( lblCTime6_font );
359 QFont cmdCity6_font( cmdCity6->font() ); 363 QFont cmdCity6_font( cmdCity6->font() );
360 cmdCity6_font.setBold( TRUE ); 364 cmdCity6_font.setBold( TRUE );
361 cmdCity6->setFont( cmdCity6_font ); 365 cmdCity6->setFont( cmdCity6_font );
362 QFont cmdCity4_font( cmdCity4->font() ); 366 QFont cmdCity4_font( cmdCity4->font() );
363 cmdCity4_font.setBold( TRUE ); 367 cmdCity4_font.setBold( TRUE );
364 cmdCity4->setFont( cmdCity4_font ); 368 cmdCity4->setFont( cmdCity4_font );
365 QFont lblCTime5_font( lblCTime5->font() ); 369 QFont lblCTime5_font( lblCTime5->font() );
366 lblCTime5_font.setPointSize( 10 ); 370 lblCTime5_font.setPointSize( 10 );
367 lblCTime5->setFont( lblCTime5_font ); 371 lblCTime5->setFont( lblCTime5_font );
368 QFont lblCTime2_font( lblCTime2->font() ); 372 QFont lblCTime2_font( lblCTime2->font() );
369 lblCTime2_font.setPointSize( 10 ); 373 lblCTime2_font.setPointSize( 10 );
370 lblCTime2->setFont( lblCTime2_font ); 374 lblCTime2->setFont( lblCTime2_font );
371 QFont lblCTime1_font( lblCTime1->font() ); 375 QFont lblCTime1_font( lblCTime1->font() );
372 lblCTime1_font.setPointSize( 10 ); 376 lblCTime1_font.setPointSize( 10 );
373 lblCTime1->setFont( lblCTime1_font ); 377 lblCTime1->setFont( lblCTime1_font );
374 QFont cmdCity3_font( cmdCity3->font() ); 378 QFont cmdCity3_font( cmdCity3->font() );
375 cmdCity3_font.setBold( TRUE ); 379 cmdCity3_font.setBold( TRUE );
376 cmdCity3->setFont( cmdCity3_font ); 380 cmdCity3->setFont( cmdCity3_font );
377 QFont lblCTime8_font( lblCTime8->font() ); 381 QFont lblCTime8_font( lblCTime8->font() );
378 lblCTime8_font.setPointSize( 10 ); 382 lblCTime8_font.setPointSize( 10 );
379 lblCTime8->setFont( lblCTime8_font ); 383 lblCTime8->setFont( lblCTime8_font );
380 QFont cmdCity1_font( cmdCity1->font() ); 384 QFont cmdCity1_font( cmdCity1->font() );
381 cmdCity1_font.setBold( TRUE ); 385 cmdCity1_font.setBold( TRUE );
382 cmdCity1->setFont( cmdCity1_font ); 386 cmdCity1->setFont( cmdCity1_font );
383 QFont lblCTime7_font( lblCTime7->font() ); 387 QFont lblCTime7_font( lblCTime7->font() );
384 lblCTime7_font.setPointSize( 10 ); 388 lblCTime7_font.setPointSize( 10 );
385 lblCTime7->setFont( lblCTime7_font ); 389 lblCTime7->setFont( lblCTime7_font );
386 QFont lblCTime4_font( lblCTime4->font() ); 390 QFont lblCTime4_font( lblCTime4->font() );
387 lblCTime4_font.setPointSize( 10 ); 391 lblCTime4_font.setPointSize( 10 );
388 lblCTime4->setFont( lblCTime4_font ); 392 lblCTime4->setFont( lblCTime4_font );
389 QFont cmdCity5_font( cmdCity5->font() ); 393 QFont cmdCity5_font( cmdCity5->font() );
390 cmdCity5_font.setBold( TRUE ); 394 cmdCity5_font.setBold( TRUE );
391 cmdCity5->setFont( cmdCity5_font ); 395 cmdCity5->setFont( cmdCity5_font );
392 QFont lblCTime3_font( lblCTime3->font() ); 396 QFont lblCTime3_font( lblCTime3->font() );
393 lblCTime3_font.setPointSize( 10 ); 397 lblCTime3_font.setPointSize( 10 );
394 lblCTime3->setFont( lblCTime3_font ); 398 lblCTime3->setFont( lblCTime3_font );
395 QFont cmdCity9_font( cmdCity9->font() ); 399 QFont cmdCity9_font( cmdCity9->font() );
396 cmdCity9_font.setBold( TRUE ); 400 cmdCity9_font.setBold( TRUE );
397 cmdCity9->setFont( cmdCity9_font ); 401 cmdCity9->setFont( cmdCity9_font );
398 } 402 }
399 return ret; 403 return ret;
400} 404}
401 405
402void CityTimeBase::beginNewTz() 406void CityTimeBase::beginNewTz()
403{ 407{
404 qWarning( "CityTimeBase::beginNewTz(): Not implemented yet!" ); 408 owarn << "CityTimeBase::beginNewTz(): Not implemented yet!" << oendl;
405} 409}
406 410
407void CityTimeBase::slotNewTz(const QString &, const QString &) 411void CityTimeBase::slotNewTz(const QString &, const QString &)
408{ 412{
409 qWarning( "CityTimeBase::slotNewTz(const QString &, const QString &): Not implemented yet!" ); 413 owarn << "CityTimeBase::slotNewTz(const QString &, const QString &): Not implemented yet!" << oendl;
410} 414}
411 415
diff --git a/core/settings/citytime/zonemap.cpp b/core/settings/citytime/zonemap.cpp
index b6843d2..e4a25ef 100644
--- a/core/settings/citytime/zonemap.cpp
+++ b/core/settings/citytime/zonemap.cpp
@@ -14,135 +14,139 @@
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 20
21// changes by Maximilian Reiss <harlekin@handhelds.org> 21// changes by Maximilian Reiss <harlekin@handhelds.org>
22 22
23#include "sun.h" 23#include "sun.h"
24#include "zonemap.h" 24#include "zonemap.h"
25 25
26/* OPIE */
26#include <qpe/resource.h> 27#include <qpe/resource.h>
27#include <qpe/qpeapplication.h> 28#include <qpe/qpeapplication.h>
29#include <opie2/odebug.h>
28 30
31/* QT */
29#include <qfile.h> 32#include <qfile.h>
30#include <qlabel.h> 33#include <qlabel.h>
31#include <qmessagebox.h> 34#include <qmessagebox.h>
32#include <qtextstream.h> 35#include <qtextstream.h>
33#include <qtimer.h> 36#include <qtimer.h>
34#include <qtoolbutton.h> 37#include <qtoolbutton.h>
35#include <qlayout.h> 38#include <qlayout.h>
36#include <qhbox.h> 39#include <qhbox.h>
37#include <qlistview.h> 40#include <qlistview.h>
38#include <qwhatsthis.h> 41#include <qwhatsthis.h>
39 42
43/* STD */
40#include <limits.h> 44#include <limits.h>
41 45
42// the map file... 46// the map file...
43static const char strZONEINFO[] = "/usr/share/zoneinfo/zone.tab"; 47static const char strZONEINFO[] = "/usr/share/zoneinfo/zone.tab";
44static const char strMAP[] = "citytime/simple_grid_400"; 48static const char strMAP[] = "citytime/simple_grid_400";
45 49
46// the maximum distance we'll allow the pointer to be away from a city 50// the maximum distance we'll allow the pointer to be away from a city
47// and still show the city's time 51// and still show the city's time
48static const int iTHRESHOLD = 50000; 52static const int iTHRESHOLD = 50000;
49 53
50// The label offset (how far away from pointer) 54// The label offset (how far away from pointer)
51static const int iLABELOFFSET = 8; 55static const int iLABELOFFSET = 8;
52 56
53// the size of the dot to draw, and where to start it 57// the size of the dot to draw, and where to start it
54static const int iCITYSIZE = 3; 58static const int iCITYSIZE = 3;
55const int iCITYOFFSET = 2; 59const int iCITYOFFSET = 2;
56 60
57// the darkening function 61// the darkening function
58static inline void darken( QImage *pImage, int start, int stop, int row ); 62static inline void darken( QImage *pImage, int start, int stop, int row );
59static void dayNight( QImage *pImage ); 63static void dayNight( QImage *pImage );
60 64
61ZoneField::ZoneField( const QString& strLine ) 65ZoneField::ZoneField( const QString& strLine )
62{ 66{
63 // make a bunch of RegExp's to match the data from the line 67 // make a bunch of RegExp's to match the data from the line
64 QRegExp regCoord( "[-+][0-9]+" );// the latitude 68 QRegExp regCoord( "[-+][0-9]+" ); // the latitude
65 QRegExp regCountry( "[A-Za-z]+/" ); // the country (not good enough) 69 QRegExp regCountry( "[A-Za-z]+/" ); // the country (not good enough)
66 QRegExp regCity( "[A-Za-z_-]*" ); // the city 70 QRegExp regCity( "[A-Za-z_-]*" ); // the city
67 71
68 int iStart, 72 int iStart,
69 iStop, 73 iStop,
70 iLen, 74 iLen,
71 tmp; 75 tmp;
72 QString strTmp; 76 QString strTmp;
73 // we should be able to assume that the country code is always the first 77 // we should be able to assume that the country code is always the first
74 // two chars, so just grap them and let it go... 78 // two chars, so just grap them and let it go...
75 strCountryCode = strLine.left( 2 ); 79 strCountryCode = strLine.left( 2 );
76 iStart = regCoord.match( strLine, 0, &iLen ); 80 iStart = regCoord.match( strLine, 0, &iLen );
77 if ( iStart >= 0 ) { 81 if ( iStart >= 0 ) {
78 strTmp = strLine.mid( iStart, iLen ); 82 strTmp = strLine.mid( iStart, iLen );
79 tmp = strTmp.toInt(); 83 tmp = strTmp.toInt();
80 // okay, there are two versions of the format, make a decision based on 84 // okay, there are two versions of the format, make a decision based on
81 // the size... 85 // the size...
82 // Oh BTW, we are storing everything in seconds! 86 // Oh BTW, we are storing everything in seconds!
83 if ( iLen < 7 ) { 87 if ( iLen < 7 ) {
84 _y = tmp / 100; 88 _y = tmp / 100;
85 _y *= 60; 89 _y *= 60;
86 _y += tmp % 100; 90 _y += tmp % 100;
87 _y *= 60; 91 _y *= 60;
88 } else { 92 } else {
89 _y = tmp / 10000; 93 _y = tmp / 10000;
90 _y *= 60; 94 _y *= 60;
91 tmp %= 10000; 95 tmp %= 10000;
92 _y += tmp / 100; 96 _y += tmp / 100;
93 _y *= 60; 97 _y *= 60;
94 tmp %= 100; 98 tmp %= 100;
95 _y += tmp; 99 _y += tmp;
96 } 100 }
97 } 101 }
98 iStart = regCoord.match( strLine, iStart + iLen, &iLen ); 102 iStart = regCoord.match( strLine, iStart + iLen, &iLen );
99 if ( iStart >= 0 ) { 103 if ( iStart >= 0 ) {
100 strTmp = strLine.mid( iStart, iLen ); 104 strTmp = strLine.mid( iStart, iLen );
101 tmp = strTmp.toInt(); 105 tmp = strTmp.toInt();
102 if ( iLen < 8 ) { 106 if ( iLen < 8 ) {
103 _x = tmp / 100; 107 _x = tmp / 100;
104 _x *= 60; 108 _x *= 60;
105 _x += tmp % 100; 109 _x += tmp % 100;
106 _x *= 60; 110 _x *= 60;
107 } else { 111 } else {
108 _x = tmp / 10000; 112 _x = tmp / 10000;
109 _x *= 60; 113 _x *= 60;
110 tmp %= 10000; 114 tmp %= 10000;
111 _x += tmp / 100; 115 _x += tmp / 100;
112 _x *= 60; 116 _x *= 60;
113 tmp %= 100; 117 tmp %= 100;
114 _x += tmp; 118 _x += tmp;
115 } 119 }
116 } 120 }
117 iStart = regCountry.match( strLine, 0, &iLen ); 121 iStart = regCountry.match( strLine, 0, &iLen );
118 // help with the shortcoming in 2.x regexp... 122 // help with the shortcoming in 2.x regexp...
119 iStop = strLine.findRev( '/' ); 123 iStop = strLine.findRev( '/' );
120 if ( iStart >= 0 ) { 124 if ( iStart >= 0 ) {
121 iLen = (iStop - iStart) + 1; 125 iLen = (iStop - iStart) + 1;
122 strCountry = strLine.mid( iStart, iLen ); 126 strCountry = strLine.mid( iStart, iLen );
123 } 127 }
124 // now match the city... 128 // now match the city...
125 iStart = regCity.match( strLine, iStart + iLen, &iLen ); 129 iStart = regCity.match( strLine, iStart + iLen, &iLen );
126 if ( iStart >= 0 ) { 130 if ( iStart >= 0 ) {
127 strCity = strLine.mid( iStart, iLen ); 131 strCity = strLine.mid( iStart, iLen );
128 } 132 }
129} 133}
130 134
131void ZoneField::showStructure( void ) const 135void ZoneField::showStructure( void ) const
132{ 136{
133 qDebug( "Country: %s", strCountry.latin1() ); 137 odebug << "Country: " << strCountry << "" << oendl;
134 qDebug( "City: %s", strCity.latin1() ); 138 odebug << "City: " << strCity << "" << oendl;
135 qDebug( "x: %d", _x ); 139 odebug << "x: " << _x << "" << oendl;
136 qDebug( "y: %d\n", _y ); 140 odebug << "y: " << _y << "\n" << oendl;
137} 141}
138 142
139ZoneMap::ZoneMap( QWidget *parent, const char* name ) 143ZoneMap::ZoneMap( QWidget *parent, const char* name )
140 : QScrollView( parent, name ), 144 : QScrollView( parent, name ),
141 pLast( 0 ), 145 pLast( 0 ),
142 pRepaint( 0 ), 146 pRepaint( 0 ),
143 ox( 0 ), 147 ox( 0 ),
144 oy( 0 ), 148 oy( 0 ),
145 drawableW( -1 ), 149 drawableW( -1 ),
146 drawableH( -1 ), 150 drawableH( -1 ),
147 bZoom( FALSE ), 151 bZoom( FALSE ),
148 bIllum( TRUE ), 152 bIllum( TRUE ),
@@ -198,138 +202,138 @@ ZoneMap::ZoneMap( QWidget *parent, const char* name )
198 // May as well read in the timezone information too... 202 // May as well read in the timezone information too...
199 readZones(); 203 readZones();
200} 204}
201 205
202ZoneMap::~ZoneMap() 206ZoneMap::~ZoneMap()
203{ 207{
204} 208}
205 209
206void ZoneMap::readZones( void ) 210void ZoneMap::readZones( void )
207{ 211{
208 QFile fZone( strZONEINFO ); 212 QFile fZone( strZONEINFO );
209 if ( !fZone.open( IO_ReadOnly ) ) { 213 if ( !fZone.open( IO_ReadOnly ) ) {
210 QMessageBox::warning (this, 214 QMessageBox::warning (this,
211 tr( "Unable to Find Timezone Info" ), 215 tr( "Unable to Find Timezone Info" ),
212 tr( "<p>Unable to find any timezone information in %1" ) 216 tr( "<p>Unable to find any timezone information in %1" )
213 .arg( strZONEINFO )); 217 .arg( strZONEINFO ));
214 exit(-1); 218 exit(-1);
215 } else { 219 } else {
216 QTextStream tZone( &fZone ); 220 QTextStream tZone( &fZone );
217 while ( !tZone.atEnd() ) { 221 while ( !tZone.atEnd() ) {
218 QString strLine = tZone.readLine(); 222 QString strLine = tZone.readLine();
219 // only pass on lines that aren't comments 223 // only pass on lines that aren't comments
220 if ( strLine[0] != '#' ) { 224 if ( strLine[0] != '#' ) {
221 zones.append( new ZoneField( strLine ) ); 225 zones.append( new ZoneField( strLine ) );
222 } 226 }
223 } 227 }
224 fZone.close(); 228 fZone.close();
225 } 229 }
226} 230}
227 231
228void ZoneMap::viewportMousePressEvent( QMouseEvent* event ) 232void ZoneMap::viewportMousePressEvent( QMouseEvent* event )
229{ 233{
230 // add the mouse event into the normalizer, and get the average, 234 // add the mouse event into the normalizer, and get the average,
231 // pass it along 235 // pass it along
232 slotRedraw(); 236 slotRedraw();
233 norm.start(); 237 norm.start();
234 norm.addEvent( event->pos() ); 238 norm.addEvent( event->pos() );
235} 239}
236 240
237void ZoneMap::viewportMouseMoveEvent( QMouseEvent* event ) 241void ZoneMap::viewportMouseMoveEvent( QMouseEvent* event )
238{ 242{
239 norm.addEvent( event->pos() ); 243 norm.addEvent( event->pos() );
240} 244}
241 245
242void ZoneMap::viewportMouseReleaseEvent( QMouseEvent* ) 246void ZoneMap::viewportMouseReleaseEvent( QMouseEvent* )
243{ 247{
244 // get the averaged points in case a timeout hasn't occurred, 248 // get the averaged points in case a timeout hasn't occurred,
245 // more for "mouse clicks" 249 // more for "mouse clicks"
246 norm.stop(); 250 norm.stop();
247 if ( pLast != NULL ) { 251 if ( pLast != NULL ) {
248 emit signalTz( pLast->country(), pLast->city() ); 252 emit signalTz( pLast->country(), pLast->city() );
249 pLast = NULL; 253 pLast = NULL;
250 } 254 }
251 tHide->start( 2000, true ); 255 tHide->start( 2000, true );
252} 256}
253 257
254void ZoneMap::keyPressEvent( QKeyEvent *ke ) 258void ZoneMap::keyPressEvent( QKeyEvent *ke )
255{ 259{
256 switch ( ke->key() ) { 260 switch ( ke->key() ) {
257 case Key_Left: 261 case Key_Left:
258 case Key_Right: 262 case Key_Right:
259 case Key_Up: 263 case Key_Up:
260 case Key_Down: { 264 case Key_Down: {
261 tHide->stop(); 265 tHide->stop();
262 if ( !cursor ) 266 if ( !cursor )
263 slotFindCity( QPoint( contentsWidth(), contentsHeight() ) / 2 ); 267 slotFindCity( QPoint( contentsWidth(), contentsHeight() ) / 2 );
264 ZoneField *city = findCityNear( cursor, ke->key() ); 268 ZoneField *city = findCityNear( cursor, ke->key() );
265 if ( city ) { 269 if ( city ) {
266 cursor = city; 270 cursor = city;
267 int tmpx, tmpy; 271 int tmpx, tmpy;
268 zoneToWin( cursor->x(), cursor->y(), tmpx, tmpy ); 272 zoneToWin( cursor->x(), cursor->y(), tmpx, tmpy );
269 ensureVisible( tmpx, tmpy ); 273 ensureVisible( tmpx, tmpy );
270 showCity( cursor ); 274 showCity( cursor );
271 tHide->start( 3000, true ); 275 tHide->start( 3000, true );
272 } 276 }
273 } 277 }
274 break; 278 break;
275 279
276 case Key_Space: 280 case Key_Space:
277 case Key_Enter: 281 case Key_Enter:
278 case Key_Return: 282 case Key_Return:
279 if ( cursor ) { 283 if ( cursor ) {
280 emit signalTz( cursor->country(), cursor->city() ); 284 emit signalTz( cursor->country(), cursor->city() );
281 tHide->start( 0, true ); 285 tHide->start( 0, true );
282 } 286 }
283 break; 287 break;
284 } 288 }
285} 289}
286 290
287ZoneField *ZoneMap::findCityNear( ZoneField *city, int key ) 291ZoneField *ZoneMap::findCityNear( ZoneField *city, int key )
288{ 292{
289 ZoneField *pZone; 293 ZoneField *pZone;
290 ZoneField *pClosest = 0; 294 ZoneField *pClosest = 0;
291 long ddist = LONG_MAX; 295 long ddist = LONG_MAX;
292 296
293 QListIterator<ZoneField> it( zones ); 297 QListIterator<ZoneField> it( zones );
294 for (; it.current(); ++it) { 298 for (; it.current(); ++it) {
295 pZone = it.current(); 299 pZone = it.current();
296 long dx = (pZone->x() - city->x())/100; 300 long dx = (pZone->x() - city->x())/100;
297 long dy = (pZone->y() - city->y())/100; 301 long dy = (pZone->y() - city->y())/100;
298 switch ( key ) { 302 switch ( key ) {
299 case Key_Right: 303 case Key_Right:
300 case Key_Left: 304 case Key_Left:
301 if ( key == Key_Left ) 305 if ( key == Key_Left )
302 dx = -dx; 306 dx = -dx;
303 if ( dx > 0 ) { 307 if ( dx > 0 ) {
304 long dist = QABS(dy)*4 + dx; 308 long dist = QABS(dy)*4 + dx;
305 if ( dist < ddist ) { 309 if ( dist < ddist ) {
306 ddist = dist; 310 ddist = dist;
307 pClosest = pZone; 311 pClosest = pZone;
308 } 312 }
309 } 313 }
310 break; 314 break;
311 case Key_Down: 315 case Key_Down:
312 case Key_Up: 316 case Key_Up:
313 if ( key == Key_Down ) 317 if ( key == Key_Down )
314 dy = -dy; 318 dy = -dy;
315 if ( dy > 0 ) { 319 if ( dy > 0 ) {
316 long dist = QABS(dx)*4 + dy; 320 long dist = QABS(dx)*4 + dy;
317 if ( dist < ddist ) { 321 if ( dist < ddist ) {
318 ddist = dist; 322 ddist = dist;
319 pClosest = pZone; 323 pClosest = pZone;
320 } 324 }
321 } 325 }
322 break; 326 break;
323 } 327 }
324 } 328 }
325 329
326 return pClosest; 330 return pClosest;
327} 331}
328 332
329void ZoneMap::slotFindCity( const QPoint &pos ) 333void ZoneMap::slotFindCity( const QPoint &pos )
330{ 334{
331 lblCity->hide(); 335 lblCity->hide();
332 // given coordinates on the screen find the closest city and display the 336 // given coordinates on the screen find the closest city and display the
333 // label close to it 337 // label close to it
334 int tmpx, tmpy, x, y; 338 int tmpx, tmpy, x, y;
335 long lDistance, 339 long lDistance,
@@ -342,145 +346,145 @@ void ZoneMap::slotFindCity( const QPoint &pos )
342 } 346 }
343 viewportToContents(pos.x(), pos.y(), tmpx, tmpy); 347 viewportToContents(pos.x(), pos.y(), tmpx, tmpy);
344 winToZone( tmpx, tmpy, x, y ); 348 winToZone( tmpx, tmpy, x, y );
345 // Find city alogorithim: start out at an (near) infinite distance away and 349 // Find city alogorithim: start out at an (near) infinite distance away and
346 // then find the closest city, (similar to the Z-buffer technique, I guess) 350 // then find the closest city, (similar to the Z-buffer technique, I guess)
347 // the only problem is that this is all done with doubles, but I don't know 351 // the only problem is that this is all done with doubles, but I don't know
348 // another way to do it at the moment. Another problem is a linked list is 352 // another way to do it at the moment. Another problem is a linked list is
349 // used obviously something indexed would help 353 // used obviously something indexed would help
350 QListIterator<ZoneField> it( zones ); 354 QListIterator<ZoneField> it( zones );
351 pClosest = 0; 355 pClosest = 0;
352 lClosest = LONG_MAX; 356 lClosest = LONG_MAX;
353 for (; it.current(); ++it) { 357 for (; it.current(); ++it) {
354 pZone = it.current(); 358 pZone = it.current();
355 // use the manhattenLength, a good enough of an appoximation here 359 // use the manhattenLength, a good enough of an appoximation here
356 lDistance = QABS( x - pZone->x() ) + QABS( y - pZone->y() ); 360 lDistance = QABS( x - pZone->x() ) + QABS( y - pZone->y() );
357 // first to zero wins! 361 // first to zero wins!
358 if ( lDistance < lClosest ) { 362 if ( lDistance < lClosest ) {
359 lClosest = lDistance; 363 lClosest = lDistance;
360 pClosest = pZone; 364 pClosest = pZone;
361 } 365 }
362 } 366 }
363 367
364 // Okay, we found the closest city, but it might still be too far away. 368 // Okay, we found the closest city, but it might still be too far away.
365 if ( lClosest <= iTHRESHOLD ) { 369 if ( lClosest <= iTHRESHOLD ) {
366 showCity( pClosest ); 370 showCity( pClosest );
367 cursor = pClosest; 371 cursor = pClosest;
368 } 372 }
369} 373}
370 374
371void ZoneMap::showCity( ZoneField *city ) 375void ZoneMap::showCity( ZoneField *city )
372{ 376{
373 pLast = city; 377 pLast = city;
374 // we'll use city and country a couple of times, get them to save some 378 // we'll use city and country a couple of times, get them to save some
375 // time 379 // time
376 QString strCity = pLast->city(); 380 QString strCity = pLast->city();
377 QString strCountry = pLast->country(); 381 QString strCountry = pLast->country();
378 // Display the time at this location by setting the environment timezone 382 // Display the time at this location by setting the environment timezone
379 // getting the current time [there] and then swapping back the variable 383 // getting the current time [there] and then swapping back the variable
380 // so no one notices... 384 // so no one notices...
381 QString strSave; 385 QString strSave;
382 char *p = getenv( "TZ" ); 386 char *p = getenv( "TZ" );
383 if ( p ) { 387 if ( p ) {
384 strSave = p; 388 strSave = p;
385 } 389 }
386 // set the timezone :) 390 // set the timezone :)
387 setenv( "TZ", strCountry + strCity, true ); 391 setenv( "TZ", strCountry + strCity, true );
388 lblCity->setText( strCity.replace( QRegExp("_"), " ") + "\n" + 392 lblCity->setText( strCity.replace( QRegExp("_"), " ") + "\n" +
389 TimeString::shortTime( ampm ) ); 393 TimeString::shortTime( ampm ) );
390 lblCity->setMinimumSize( lblCity->sizeHint() ); 394 lblCity->setMinimumSize( lblCity->sizeHint() );
391 // undue our damage... 395 // undue our damage...
392 unsetenv( "TZ" ); 396 unsetenv( "TZ" );
393 if ( p ) 397 if ( p )
394 setenv( "TZ", strSave, true ); 398 setenv( "TZ", strSave, true );
395 // Now decide where to move the label, x & y can be reused 399 // Now decide where to move the label, x & y can be reused
396 int tmpx, tmpy, x, y; 400 int tmpx, tmpy, x, y;
397 zoneToWin( pLast->x(), pLast->y(), tmpx, tmpy ); 401 zoneToWin( pLast->x(), pLast->y(), tmpx, tmpy );
398 contentsToViewport(tmpx, tmpy, x, y); 402 contentsToViewport(tmpx, tmpy, x, y);
399 if ( lblCity->width() > drawableW - x ) { 403 if ( lblCity->width() > drawableW - x ) {
400 // oops... try putting it on the right 404 // oops... try putting it on the right
401 x = x - lblCity->width() - iLABELOFFSET; 405 x = x - lblCity->width() - iLABELOFFSET;
402 } else { 406 } else {
403 // the default... 407 // the default...
404 x += iLABELOFFSET; 408 x += iLABELOFFSET;
405 } 409 }
406 if ( lblCity->height() > drawableH - y ) { 410 if ( lblCity->height() > drawableH - y ) {
407 // move it up... 411 // move it up...
408 y = y - lblCity->height() - iLABELOFFSET; 412 y = y - lblCity->height() - iLABELOFFSET;
409 } else if ( y < 0 ) { 413 } else if ( y < 0 ) {
410 // the city is actually off the screen... 414 // the city is actually off the screen...
411 // this only happens on the a zoom when you are near the top, 415 // this only happens on the a zoom when you are near the top,
412 // a quick workaround.. 416 // a quick workaround..
413 y = iLABELOFFSET; 417 y = iLABELOFFSET;
414 } else { 418 } else {
415 // the default 419 // the default
416 y += iLABELOFFSET; 420 y += iLABELOFFSET;
417 } 421 }
418 422
419 // draw in the city and the label 423 // draw in the city and the label
420 if ( pRepaint ) { 424 if ( pRepaint ) {
421 int repx, 425 int repx,
422 repy; 426 repy;
423 zoneToWin( pRepaint->x(), pRepaint->y(), repx, repy ); 427 zoneToWin( pRepaint->x(), pRepaint->y(), repx, repy );
424 updateContents( repx - iCITYOFFSET, repy - iCITYOFFSET, 428 updateContents( repx - iCITYOFFSET, repy - iCITYOFFSET,
425 iCITYSIZE, iCITYSIZE ); 429 iCITYSIZE, iCITYSIZE );
426 } 430 }
427 updateContents( tmpx - iCITYOFFSET, tmpy - iCITYOFFSET, iCITYSIZE, 431 updateContents( tmpx - iCITYOFFSET, tmpy - iCITYOFFSET, iCITYSIZE,
428 iCITYSIZE ); 432 iCITYSIZE );
429 pRepaint = pLast; 433 pRepaint = pLast;
430 434
431 lblCity->move( x, y ); 435 lblCity->move( x, y );
432 lblCity->show(); 436 lblCity->show();
433} 437}
434 438
435void ZoneMap::resizeEvent( QResizeEvent *e ) 439void ZoneMap::resizeEvent( QResizeEvent *e )
436{ 440{
437 // keep the zoom button down in the corner 441 // keep the zoom button down in the corner
438 QSize _size = e->size(); 442 QSize _size = e->size();
439 cmdZoom->move( _size.width() - cmdZoom->width(), 443 cmdZoom->move( _size.width() - cmdZoom->width(),
440 _size.height() - cmdZoom->height() ); 444 _size.height() - cmdZoom->height() );
441 if ( !bZoom ) { 445 if ( !bZoom ) {
442 drawableW = width() - 2 * frameWidth(); 446 drawableW = width() - 2 * frameWidth();
443 drawableH = height() - 2 * frameWidth(); 447 drawableH = height() - 2 * frameWidth();
444 makeMap( drawableW, drawableH ); 448 makeMap( drawableW, drawableH );
445 resizeContents( drawableW, drawableH ); 449 resizeContents( drawableW, drawableH );
446 } 450 }
447} 451}
448 452
449void ZoneMap::showZones( void ) const 453void ZoneMap::showZones( void ) const
450{ 454{
451 // go through the zones in the list and just display the values... 455 // go through the zones in the list and just display the values...
452 QListIterator<ZoneField> itZone( zones ); 456 QListIterator<ZoneField> itZone( zones );
453 for ( itZone.toFirst(); itZone.current(); ++itZone ) { 457 for ( itZone.toFirst(); itZone.current(); ++itZone ) {
454 ZoneField *pZone = itZone.current(); 458 ZoneField *pZone = itZone.current();
455 pZone->showStructure(); 459 pZone->showStructure();
456 } 460 }
457} 461}
458 462
459 463
460QWidget* ZoneMap::selectionWidget( QWidget *parent) { 464QWidget* ZoneMap::selectionWidget( QWidget *parent) {
461 465
462 QWidget *returnWidget = new QWidget( parent ); 466 QWidget *returnWidget = new QWidget( parent );
463 467
464 QVBoxLayout *layout = new QVBoxLayout( returnWidget ); 468 QVBoxLayout *layout = new QVBoxLayout( returnWidget );
465 QHBox *hBox = new QHBox( returnWidget ); 469 QHBox *hBox = new QHBox( returnWidget );
466 QListView *continentView = new QListView( hBox ); 470 QListView *continentView = new QListView( hBox );
467 continentView->addColumn( tr("Continent") ); 471 continentView->addColumn( tr("Continent") );
468 QWhatsThis::add( continentView, tr("Select a continent/country here, then select a city") ); 472 QWhatsThis::add( continentView, tr("Select a continent/country here, then select a city") );
469 connect ( continentView, SIGNAL( clicked(QListViewItem*) ), this, SLOT( slotGetCities(QListViewItem*) ) ); 473 connect ( continentView, SIGNAL( clicked(QListViewItem*) ), this, SLOT( slotGetCities(QListViewItem*) ) );
470 474
471 QStringList continentList; 475 QStringList continentList;
472 QListIterator<ZoneField> itZone( zones ); 476 QListIterator<ZoneField> itZone( zones );
473 for ( itZone.toFirst(); itZone.current(); ++itZone ) { 477 for ( itZone.toFirst(); itZone.current(); ++itZone ) {
474 ZoneField *pZone = itZone.current(); 478 ZoneField *pZone = itZone.current();
475 if ( continentList.contains( pZone->country() ) == 0 ) { 479 if ( continentList.contains( pZone->country() ) == 0 ) {
476 QString name; 480 QString name;
477 QListViewItem *item; 481 QListViewItem *item;
478 if ( !(pZone->country().length() > 24) ) { 482 if ( !(pZone->country().length() > 24) ) {
479 name = pZone->country().left(pZone->country().length()-1 ); 483 name = pZone->country().left(pZone->country().length()-1 );
480 } else { 484 } else {
481 name = pZone->country().left( 24 ); 485 name = pZone->country().left( 24 );
482 } 486 }
483 item = new QListViewItem( continentView, name, pZone->country() ); 487 item = new QListViewItem( continentView, name, pZone->country() );
484 continentList.append( pZone->country() ); 488 continentList.append( pZone->country() );
485 } 489 }
486 } 490 }
@@ -489,53 +493,53 @@ QWidget* ZoneMap::selectionWidget( QWidget *parent) {
489 cityView->addColumn( tr("City") ); 493 cityView->addColumn( tr("City") );
490 494
491 layout->addWidget( hBox ); 495 layout->addWidget( hBox );
492 return returnWidget; 496 return returnWidget;
493} 497}
494 498
495void ZoneMap::slotGetCities( QListViewItem * contItem) { 499void ZoneMap::slotGetCities( QListViewItem * contItem) {
496 500
497 cityView->clear(); 501 cityView->clear();
498 selectedCont = contItem->text( 1 ); 502 selectedCont = contItem->text( 1 );
499 QListIterator<ZoneField> itZone( zones ); 503 QListIterator<ZoneField> itZone( zones );
500 for ( itZone.toFirst(); itZone.current(); ++itZone ) { 504 for ( itZone.toFirst(); itZone.current(); ++itZone ) {
501 ZoneField *pZone = itZone.current(); 505 ZoneField *pZone = itZone.current();
502 if ( pZone->country() == contItem->text( 1 ) ) { 506 if ( pZone->country() == contItem->text( 1 ) ) {
503 QListViewItem *item; 507 QListViewItem *item;
504 item = new QListViewItem( cityView, pZone->city() ); 508 item = new QListViewItem( cityView, pZone->city() );
505 connect ( cityView, SIGNAL( clicked(QListViewItem*) ), this, SLOT( slotCitySelected(QListViewItem*) ) ); 509 connect ( cityView, SIGNAL( clicked(QListViewItem*) ), this, SLOT( slotCitySelected(QListViewItem*) ) );
506 } 510 }
507 } 511 }
508} 512}
509 513
510void ZoneMap::slotCitySelected( QListViewItem *cityItem ) { 514void ZoneMap::slotCitySelected( QListViewItem *cityItem ) {
511 if ( cityItem ) { 515 if ( cityItem ) {
512 emit signalTz( selectedCont, cityItem->text( 0 ) ); 516 emit signalTz( selectedCont, cityItem->text( 0 ) );
513 } 517 }
514} 518}
515 519
516void ZoneMap::drawCities( QPainter *p ) 520void ZoneMap::drawCities( QPainter *p )
517{ 521{
518 int x, y, j; 522 int x, y, j;
519 // draw in the cities 523 // draw in the cities
520 // for testing only as when you put it 524 // for testing only as when you put it
521 // on the small screen it looks awful and not to mention useless 525 // on the small screen it looks awful and not to mention useless
522 p->setPen( red ); 526 p->setPen( red );
523 QListIterator<ZoneField> itZone( zones ); 527 QListIterator<ZoneField> itZone( zones );
524 for ( itZone.toFirst(), j = 0; itZone.current(); ++itZone, j++ ) { 528 for ( itZone.toFirst(), j = 0; itZone.current(); ++itZone, j++ ) {
525 ZoneField *pZone = itZone.current(); 529 ZoneField *pZone = itZone.current();
526 zoneToWin( pZone->x(), pZone->y(), x, y ); 530 zoneToWin( pZone->x(), pZone->y(), x, y );
527 if ( x > wImg ) 531 if ( x > wImg )
528 x = x - wImg; 532 x = x - wImg;
529 p->drawRect( x - iCITYOFFSET, y - iCITYOFFSET, iCITYSIZE, iCITYSIZE); 533 p->drawRect( x - iCITYOFFSET, y - iCITYOFFSET, iCITYSIZE, iCITYSIZE);
530 } 534 }
531} 535}
532 536
533static void dayNight(QImage *pImage) 537static void dayNight(QImage *pImage)
534{ 538{
535 // create a mask the functions from sun.h 539 // create a mask the functions from sun.h
536 double dJulian, 540 double dJulian,
537 dSunRad, 541 dSunRad,
538 dSunDecl, 542 dSunDecl,
539 dSunRadius, 543 dSunRadius,
540 dSunLong; 544 dSunLong;
541 int wImage = pImage->width(), 545 int wImage = pImage->width(),
@@ -554,84 +558,84 @@ static void dayNight(QImage *pImage)
554 pTm = gmtime( &tCurrent ); 558 pTm = gmtime( &tCurrent );
555 dJulian = jtime( pTm ); 559 dJulian = jtime( pTm );
556 sunpos( dJulian, 0, &dSunRad, &dSunDecl, &dSunRadius, &dSunLong ); 560 sunpos( dJulian, 0, &dSunRad, &dSunDecl, &dSunRadius, &dSunLong );
557 561
558 // now get the projected illumination 562 // now get the projected illumination
559 projillum( wtab, wImage, hImage, dSunDecl ); 563 projillum( wtab, wImage, hImage, dSunDecl );
560 relw = wImage - int( wImage * 0.0275 ); 564 relw = wImage - int( wImage * 0.0275 );
561 565
562 // draw the map, keeping in mind that we may go too far off the map... 566 // draw the map, keeping in mind that we may go too far off the map...
563 iMid = ( relw * ( 24*60 - pTm->tm_hour * 60 - pTm->tm_min ) ) / ( 24*60 ); 567 iMid = ( relw * ( 24*60 - pTm->tm_hour * 60 - pTm->tm_min ) ) / ( 24*60 );
564 568
565 for ( i = 0; i < hImage; i++ ) { 569 for ( i = 0; i < hImage; i++ ) {
566 if ( wtab[i] > 0 ) { 570 if ( wtab[i] > 0 ) {
567 iStart = iMid - wtab[i]; 571 iStart = iMid - wtab[i];
568 iStop = iMid + wtab[i]; 572 iStop = iMid + wtab[i];
569 if ( iStart < 0 ) { 573 if ( iStart < 0 ) {
570 darken( pImage, iStop, wImage + iStart, i ); 574 darken( pImage, iStop, wImage + iStart, i );
571 } else if ( iStop > wImage ) { 575 } else if ( iStop > wImage ) {
572 darken( pImage, iStop - wImage, iStart, i ); 576 darken( pImage, iStop - wImage, iStart, i );
573 } else { 577 } else {
574 darken( pImage, 0, iStart, i ); 578 darken( pImage, 0, iStart, i );
575 darken( pImage, iStop, wImage, i ); 579 darken( pImage, iStop, wImage, i );
576 } 580 }
577 } else { 581 } else {
578 darken( pImage, 0, wImage, i ); 582 darken( pImage, 0, wImage, i );
579 } 583 }
580 } 584 }
581} 585}
582 586
583static inline void darken( QImage *pImage, int start, int stop, int row ) 587static inline void darken( QImage *pImage, int start, int stop, int row )
584{ 588{
585 int colors, 589 int colors,
586 j; 590 j;
587 uchar *p; 591 uchar *p;
588 592
589 // assume that the image is similar to the one we have... 593 // assume that the image is similar to the one we have...
590 colors = pImage->numColors() / 2; 594 colors = pImage->numColors() / 2;
591 595
592 p = pImage->scanLine( row ); 596 p = pImage->scanLine( row );
593 for ( j = start; j <= stop; j++ ) { 597 for ( j = start; j <= stop; j++ ) {
594 if ( p[j] < colors ) 598 if ( p[j] < colors )
595 p[j] += colors; 599 p[j] += colors;
596 } 600 }
597} 601}
598 602
599void ZoneMap::makeMap( int w, int h ) 603void ZoneMap::makeMap( int w, int h )
600{ 604{
601 QImage imgOrig = Resource::loadImage( strMAP ); 605 QImage imgOrig = Resource::loadImage( strMAP );
602 if ( imgOrig.isNull() ) { 606 if ( imgOrig.isNull() ) {
603 QMessageBox::warning( this, 607 QMessageBox::warning( this,
604 tr( "Couldn't Find Map" ), 608 tr( "Couldn't Find Map" ),
605 tr( "<p>Couldn't load map: %1, exiting") 609 tr( "<p>Couldn't load map: %1, exiting")
606 .arg( strMAP ) ); 610 .arg( strMAP ) );
607 exit(-1); 611 exit(-1);
608 } 612 }
609 613
610 // set up the color table for darkening... 614 // set up the color table for darkening...
611 imgOrig = imgOrig.convertDepth( 8 ); 615 imgOrig = imgOrig.convertDepth( 8 );
612 int numColors = imgOrig.numColors(); 616 int numColors = imgOrig.numColors();
613 // double the colors 617 // double the colors
614 imgOrig.setNumColors( 2 * numColors ); 618 imgOrig.setNumColors( 2 * numColors );
615 // darken the new ones... 619 // darken the new ones...
616 for ( int i = 0; i < numColors; i++ ) { 620 for ( int i = 0; i < numColors; i++ ) {
617 QRgb rgb = imgOrig.color( i ); 621 QRgb rgb = imgOrig.color( i );
618 imgOrig.setColor ( i + numColors, qRgb( 2 * qRed( rgb ) / 3, 622 imgOrig.setColor ( i + numColors, qRgb( 2 * qRed( rgb ) / 3,
619 2 * qGreen( rgb ) / 3, 2 * qBlue( rgb ) / 3 ) ); 623 2 * qGreen( rgb ) / 3, 2 * qBlue( rgb ) / 3 ) );
620 } 624 }
621 625
622 // else go one with making the map... 626 // else go one with making the map...
623 if ( bIllum ) { 627 if ( bIllum ) {
624 // do a daylight mask 628 // do a daylight mask
625 dayNight(&imgOrig); 629 dayNight(&imgOrig);
626 } 630 }
627 // redo the width and height 631 // redo the width and height
628 wImg = w; 632 wImg = w;
629 hImg = h; 633 hImg = h;
630 ox = ( wImg / 2 ) - int( wImg * 0.0275 ); 634 ox = ( wImg / 2 ) - int( wImg * 0.0275 );
631 oy = hImg / 2; 635 oy = hImg / 2;
632 pixCurr->convertFromImage( imgOrig.smoothScale(w, h), 636 pixCurr->convertFromImage( imgOrig.smoothScale(w, h),
633 QPixmap::ThresholdDither ); 637 QPixmap::ThresholdDither );
634} 638}
635 639
636void ZoneMap::drawCity( QPainter *p, const ZoneField *pCity ) 640void ZoneMap::drawCity( QPainter *p, const ZoneField *pCity )
637{ 641{
@@ -645,56 +649,56 @@ void ZoneMap::drawCity( QPainter *p, const ZoneField *pCity )
645 649
646void ZoneMap::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) 650void ZoneMap::drawContents( QPainter *p, int cx, int cy, int cw, int ch )
647{ 651{
648 // if there is a need to resize, then do it... 652 // if there is a need to resize, then do it...
649 // get our drawable area 653 // get our drawable area
650 drawableW = width() - 2 * frameWidth(); 654 drawableW = width() - 2 * frameWidth();
651 drawableH = height() - 2 * frameWidth(); 655 drawableH = height() - 2 * frameWidth();
652 656
653 int pixmapW = pixCurr->width(), 657 int pixmapW = pixCurr->width(),
654 pixmapH = pixCurr->height(); 658 pixmapH = pixCurr->height();
655 if ( !bZoom && ( ( pixmapW != drawableW ) || 659 if ( !bZoom && ( ( pixmapW != drawableW ) ||
656 ( pixmapH != drawableH) ) ) { 660 ( pixmapH != drawableH) ) ) {
657 makeMap( drawableW, drawableH ); 661 makeMap( drawableW, drawableH );
658 } 662 }
659 663
660 // taken from the scrollview example... 664 // taken from the scrollview example...
661 int rowheight = pixCurr->height(); 665 int rowheight = pixCurr->height();
662 int toprow = cy / rowheight; 666 int toprow = cy / rowheight;
663 int bottomrow = ( cy + ch + rowheight - 1 ) / rowheight; 667 int bottomrow = ( cy + ch + rowheight - 1 ) / rowheight;
664 int colwidth = pixCurr->width(); 668 int colwidth = pixCurr->width();
665 int leftcol= cx / colwidth; 669 int leftcol= cx / colwidth;
666 int rightcol= ( cx + cw + colwidth - 1 ) / colwidth; 670 int rightcol= ( cx + cw + colwidth - 1 ) / colwidth;
667 for ( int r = toprow; r <= bottomrow; r++ ) { 671 for ( int r = toprow; r <= bottomrow; r++ ) {
668 int py = r * rowheight; 672 int py = r * rowheight;
669 for ( int c = leftcol; c <= rightcol; c++ ) { 673 for ( int c = leftcol; c <= rightcol; c++ ) {
670 int px = c * colwidth; 674 int px = c * colwidth;
671 p->drawPixmap( px, py, *pixCurr ); 675 p->drawPixmap( px, py, *pixCurr );
672 } 676 }
673 } 677 }
674 678
675 // Draw that city! 679 // Draw that city!
676 if ( pLast ) 680 if ( pLast )
677 drawCity( p, pLast ); 681 drawCity( p, pLast );
678} 682}
679 683
680void ZoneMap::slotZoom( bool setZoom ) 684void ZoneMap::slotZoom( bool setZoom )
681{ 685{
682 bZoom = setZoom; 686 bZoom = setZoom;
683 if ( bZoom ) { 687 if ( bZoom ) {
684 makeMap( 2 * wImg , 2 * hImg ); 688 makeMap( 2 * wImg , 2 * hImg );
685 resizeContents( wImg, hImg ); 689 resizeContents( wImg, hImg );
686 } else { 690 } else {
687 makeMap( drawableW, drawableH ); 691 makeMap( drawableW, drawableH );
688 resizeContents( drawableW, drawableH ); 692 resizeContents( drawableW, drawableH );
689 } 693 }
690} 694}
691 695
692void ZoneMap::slotIllum( bool setIllum ) 696void ZoneMap::slotIllum( bool setIllum )
693{ 697{
694 bIllum = !setIllum; 698 bIllum = !setIllum;
695 // make the map... 699 // make the map...
696 makeMap( pixCurr->width(), pixCurr->height() ); 700 makeMap( pixCurr->width(), pixCurr->height() );
697 updateContents( 0, 0, wImg, hImg ); 701 updateContents( 0, 0, wImg, hImg );
698} 702}
699 703
700void ZoneMap::slotUpdate( void ) 704void ZoneMap::slotUpdate( void )
@@ -702,23 +706,23 @@ void ZoneMap::slotUpdate( void )
702 // recalculate the light, most people will never see this, 706 // recalculate the light, most people will never see this,
703 // but it is good to be complete 707 // but it is good to be complete
704 makeMap ( pixCurr->width(), pixCurr->height() ); 708 makeMap ( pixCurr->width(), pixCurr->height() );
705 updateContents( contentsX(), contentsY(), drawableW, drawableH ); 709 updateContents( contentsX(), contentsY(), drawableW, drawableH );
706} 710}
707 711
708void ZoneMap::slotRedraw( void ) 712void ZoneMap::slotRedraw( void )
709{ 713{
710 // paint over that pesky city... 714 // paint over that pesky city...
711 int x, 715 int x,
712 y; 716 y;
713 if ( pRepaint ) { 717 if ( pRepaint ) {
714 pLast = 0; 718 pLast = 0;
715 zoneToWin(pRepaint->x(), pRepaint->y(), x, y); 719 zoneToWin(pRepaint->x(), pRepaint->y(), x, y);
716 updateContents( x - iCITYOFFSET, y - iCITYOFFSET, iCITYSIZE, iCITYSIZE); 720 updateContents( x - iCITYOFFSET, y - iCITYOFFSET, iCITYSIZE, iCITYSIZE);
717 pRepaint = 0; 721 pRepaint = 0;
718 } 722 }
719} 723}
720 724
721void ZoneMap::changeClock( bool whichClock ) 725void ZoneMap::changeClock( bool whichClock )
722{ 726{
723 ampm = whichClock; 727 ampm = whichClock;
724} 728}