summaryrefslogtreecommitdiff
path: root/core/settings/citytime/zonemap.cpp
Unidiff
Diffstat (limited to 'core/settings/citytime/zonemap.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/settings/citytime/zonemap.cpp402
1 files changed, 203 insertions, 199 deletions
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
@@ -20,26 +20,30 @@
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
@@ -58,85 +62,85 @@ const int iCITYOFFSET = 2;
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 ),
@@ -204,27 +208,27 @@ ZoneMap::~ZoneMap()
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,
@@ -242,88 +246,88 @@ void ZoneMap::viewportMouseMoveEvent( QMouseEvent* event )
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 )
@@ -348,26 +352,26 @@ void ZoneMap::slotFindCity( const QPoint &pos )
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;
@@ -378,57 +382,57 @@ void ZoneMap::showCity( ZoneField *city )
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
@@ -436,26 +440,26 @@ void 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
@@ -468,13 +472,13 @@ QWidget* ZoneMap::selectionWidget( QWidget *parent) {
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 {
@@ -495,13 +499,13 @@ QWidget* ZoneMap::selectionWidget( QWidget *parent) {
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 }
@@ -519,17 +523,17 @@ void ZoneMap::drawCities( QPainter *p )
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
@@ -560,26 +564,26 @@ static void dayNight(QImage *pImage)
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,
@@ -588,44 +592,44 @@ static inline void darken( QImage *pImage, int start, int stop, int row )
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;
@@ -651,44 +655,44 @@ void ZoneMap::drawContents( QPainter *p, int cx, int cy, int cw, int ch )
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;
@@ -708,15 +712,15 @@ void ZoneMap::slotUpdate( void )
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{