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
@@ -25,5 +25,8 @@
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>
@@ -39,2 +42,3 @@
39 42
43/* STD */
40#include <limits.h> 44#include <limits.h>
@@ -63,3 +67,3 @@ ZoneField::ZoneField( const QString& strLine )
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)
@@ -68,3 +72,3 @@ ZoneField::ZoneField( const QString& strLine )
68 int iStart, 72 int iStart,
69 iStop, 73 iStop,
70 iLen, 74 iLen,
@@ -77,21 +81,21 @@ ZoneField::ZoneField( const QString& strLine )
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 }
@@ -99,18 +103,18 @@ ZoneField::ZoneField( const QString& strLine )
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 }
@@ -120,4 +124,4 @@ ZoneField::ZoneField( const QString& strLine )
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 }
@@ -126,3 +130,3 @@ ZoneField::ZoneField( const QString& strLine )
126 if ( iStart >= 0 ) { 130 if ( iStart >= 0 ) {
127 strCity = strLine.mid( iStart, iLen ); 131 strCity = strLine.mid( iStart, iLen );
128 } 132 }
@@ -132,6 +136,6 @@ void 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}
@@ -209,17 +213,17 @@ void ZoneMap::readZones( void )
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 }
@@ -247,4 +251,4 @@ void ZoneMap::viewportMouseReleaseEvent( QMouseEvent* )
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 }
@@ -256,29 +260,29 @@ void ZoneMap::keyPressEvent( QKeyEvent *ke )
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 }
@@ -294,31 +298,31 @@ ZoneField *ZoneMap::findCityNear( ZoneField *city, int key )
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 }
@@ -353,10 +357,10 @@ void ZoneMap::slotFindCity( const QPoint &pos )
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 }
@@ -365,4 +369,4 @@ void ZoneMap::slotFindCity( const QPoint &pos )
365 if ( lClosest <= iTHRESHOLD ) { 369 if ( lClosest <= iTHRESHOLD ) {
366 showCity( pClosest ); 370 showCity( pClosest );
367 cursor = pClosest; 371 cursor = pClosest;
368 } 372 }
@@ -383,3 +387,3 @@ void ZoneMap::showCity( ZoneField *city )
383 if ( p ) { 387 if ( p ) {
384 strSave = p; 388 strSave = p;
385 } 389 }
@@ -388,3 +392,3 @@ void ZoneMap::showCity( ZoneField *city )
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() );
@@ -393,3 +397,3 @@ void ZoneMap::showCity( ZoneField *city )
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
@@ -399,19 +403,19 @@ void ZoneMap::showCity( ZoneField *city )
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 }
@@ -420,10 +424,10 @@ void ZoneMap::showCity( ZoneField *city )
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;
@@ -441,6 +445,6 @@ void ZoneMap::resizeEvent( QResizeEvent *e )
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 }
@@ -453,4 +457,4 @@ void ZoneMap::showZones( void ) const
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 }
@@ -473,3 +477,3 @@ QWidget* ZoneMap::selectionWidget( QWidget *parent) {
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 ) {
@@ -500,3 +504,3 @@ void ZoneMap::slotGetCities( QListViewItem * contItem) {
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 ) ) {
@@ -524,7 +528,7 @@ void ZoneMap::drawCities( QPainter *p )
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 }
@@ -565,16 +569,16 @@ static void dayNight(QImage *pImage)
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 }
@@ -593,4 +597,4 @@ static inline void darken( QImage *pImage, int start, int stop, int 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 }
@@ -602,7 +606,7 @@ void ZoneMap::makeMap( int w, int h )
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 }
@@ -616,5 +620,5 @@ void ZoneMap::makeMap( int w, int h )
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 }
@@ -623,4 +627,4 @@ void ZoneMap::makeMap( int w, int h )
623 if ( bIllum ) { 627 if ( bIllum ) {
624 // do a daylight mask 628 // do a daylight mask
625 dayNight(&imgOrig); 629 dayNight(&imgOrig);
626 } 630 }
@@ -656,3 +660,3 @@ void ZoneMap::drawContents( QPainter *p, int cx, int cy, int cw, int ch )
656 ( pixmapH != drawableH) ) ) { 660 ( pixmapH != drawableH) ) ) {
657 makeMap( drawableW, drawableH ); 661 makeMap( drawableW, drawableH );
658 } 662 }
@@ -667,7 +671,7 @@ void ZoneMap::drawContents( QPainter *p, int cx, int cy, int cw, int ch )
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 }
@@ -676,3 +680,3 @@ void ZoneMap::drawContents( QPainter *p, int cx, int cy, int cw, int ch )
676 if ( pLast ) 680 if ( pLast )
677 drawCity( p, pLast ); 681 drawCity( p, pLast );
678} 682}
@@ -683,7 +687,7 @@ void ZoneMap::slotZoom( bool 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 }
@@ -713,5 +717,5 @@ void ZoneMap::slotRedraw( void )
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;