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.cpp67
1 files changed, 64 insertions, 3 deletions
diff --git a/core/settings/citytime/zonemap.cpp b/core/settings/citytime/zonemap.cpp
index 1d60aee..872e786 100644
--- a/core/settings/citytime/zonemap.cpp
+++ b/core/settings/citytime/zonemap.cpp
@@ -1,87 +1,93 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21// changes by Maximilian Reiss <harlekin@handhelds.org>
22
21#include "sun.h" 23#include "sun.h"
22#include "zonemap.h" 24#include "zonemap.h"
23 25
24#include <qpe/resource.h> 26#include <qpe/resource.h>
25#include <qpe/timestring.h> 27#include <qpe/timestring.h>
26#include <qpe/qpeapplication.h> 28#include <qpe/qpeapplication.h>
27 29
28#include <qdatetime.h> 30#include <qdatetime.h>
29#include <qfile.h> 31#include <qfile.h>
30#include <qimage.h> 32#include <qimage.h>
31#include <qlabel.h> 33#include <qlabel.h>
32#include <qlist.h> 34#include <qlist.h>
33#include <qmessagebox.h> 35#include <qmessagebox.h>
34#include <qpixmap.h> 36#include <qpixmap.h>
35#include <qpainter.h> 37#include <qpainter.h>
36#include <qregexp.h> 38#include <qregexp.h>
37#include <qtextstream.h> 39#include <qtextstream.h>
38#include <qtimer.h> 40#include <qtimer.h>
39#include <qtoolbutton.h> 41#include <qtoolbutton.h>
42#include <qlayout.h>
43#include <qhbox.h>
44#include <qlistview.h>
45#include <qwhatsthis.h>
40 46
41#include <limits.h> 47#include <limits.h>
42 48
43// the map file... 49// the map file...
44static const char strZONEINFO[] = "/usr/share/zoneinfo/zone.tab"; 50static const char strZONEINFO[] = "/usr/share/zoneinfo/zone.tab";
45static const char strMAP[] = "citytime/simple_grid_400"; 51static const char strMAP[] = "citytime/simple_grid_400";
46 52
47// the maximum distance we'll allow the pointer to be away from a city 53// the maximum distance we'll allow the pointer to be away from a city
48// and still show the city's time 54// and still show the city's time
49static const int iTHRESHOLD = 50000; 55static const int iTHRESHOLD = 50000;
50 56
51// The label offset (how far away from pointer) 57// The label offset (how far away from pointer)
52static const int iLABELOFFSET = 8; 58static const int iLABELOFFSET = 8;
53 59
54// the size of the dot to draw, and where to start it 60// the size of the dot to draw, and where to start it
55static const int iCITYSIZE = 3; 61static const int iCITYSIZE = 3;
56const int iCITYOFFSET = 2; 62const int iCITYOFFSET = 2;
57 63
58// the darkening function 64// the darkening function
59static inline void darken( QImage *pImage, int start, int stop, int row ); 65static inline void darken( QImage *pImage, int start, int stop, int row );
60static void dayNight( QImage *pImage ); 66static void dayNight( QImage *pImage );
61 67
62ZoneField::ZoneField( const QString& strLine ) 68ZoneField::ZoneField( const QString& strLine )
63{ 69{
64 // make a bunch of RegExp's to match the data from the line 70 // make a bunch of RegExp's to match the data from the line
65 QRegExp regCoord( "[-+][0-9]+" );// the latitude 71 QRegExp regCoord( "[-+][0-9]+" );// the latitude
66 QRegExp regCountry( "[A-Za-z]+/" ); // the country (not good enough) 72 QRegExp regCountry( "[A-Za-z]+/" ); // the country (not good enough)
67 QRegExp regCity( "[A-Za-z_-]*" ); // the city 73 QRegExp regCity( "[A-Za-z_-]*" ); // the city
68 74
69 int iStart, 75 int iStart,
70 iStop, 76 iStop,
71 iLen, 77 iLen,
72 tmp; 78 tmp;
73 QString strTmp; 79 QString strTmp;
74 // we should be able to assume that the country code is always the first 80 // we should be able to assume that the country code is always the first
75 // two chars, so just grap them and let it go... 81 // two chars, so just grap them and let it go...
76 strCountryCode = strLine.left( 2 ); 82 strCountryCode = strLine.left( 2 );
77 iStart = regCoord.match( strLine, 0, &iLen ); 83 iStart = regCoord.match( strLine, 0, &iLen );
78 if ( iStart >= 0 ) { 84 if ( iStart >= 0 ) {
79 strTmp = strLine.mid( iStart, iLen ); 85 strTmp = strLine.mid( iStart, iLen );
80 tmp = strTmp.toInt(); 86 tmp = strTmp.toInt();
81 // okay, there are two versions of the format, make a decision based on 87 // okay, there are two versions of the format, make a decision based on
82 // the size... 88 // the size...
83 // Oh BTW, we are storing everything in seconds! 89 // Oh BTW, we are storing everything in seconds!
84 if ( iLen < 7 ) { 90 if ( iLen < 7 ) {
85 _y = tmp / 100; 91 _y = tmp / 100;
86 _y *= 60; 92 _y *= 60;
87 _y += tmp % 100; 93 _y += tmp % 100;
@@ -412,101 +418,156 @@ void ZoneMap::showCity( ZoneField *city )
412 // this only happens on the a zoom when you are near the top, 418 // this only happens on the a zoom when you are near the top,
413 // a quick workaround.. 419 // a quick workaround..
414 y = iLABELOFFSET; 420 y = iLABELOFFSET;
415 } else { 421 } else {
416 // the default 422 // the default
417 y += iLABELOFFSET; 423 y += iLABELOFFSET;
418 } 424 }
419 425
420 // draw in the city and the label 426 // draw in the city and the label
421 if ( pRepaint ) { 427 if ( pRepaint ) {
422 int repx, 428 int repx,
423 repy; 429 repy;
424 zoneToWin( pRepaint->x(), pRepaint->y(), repx, repy ); 430 zoneToWin( pRepaint->x(), pRepaint->y(), repx, repy );
425 updateContents( repx - iCITYOFFSET, repy - iCITYOFFSET, 431 updateContents( repx - iCITYOFFSET, repy - iCITYOFFSET,
426 iCITYSIZE, iCITYSIZE ); 432 iCITYSIZE, iCITYSIZE );
427 } 433 }
428 updateContents( tmpx - iCITYOFFSET, tmpy - iCITYOFFSET, iCITYSIZE, 434 updateContents( tmpx - iCITYOFFSET, tmpy - iCITYOFFSET, iCITYSIZE,
429 iCITYSIZE ); 435 iCITYSIZE );
430 pRepaint = pLast; 436 pRepaint = pLast;
431 437
432 lblCity->move( x, y ); 438 lblCity->move( x, y );
433 lblCity->show(); 439 lblCity->show();
434} 440}
435 441
436void ZoneMap::resizeEvent( QResizeEvent *e ) 442void ZoneMap::resizeEvent( QResizeEvent *e )
437{ 443{
438 // keep the zoom button down in the corner 444 // keep the zoom button down in the corner
439 QSize _size = e->size(); 445 QSize _size = e->size();
440 cmdZoom->move( _size.width() - cmdZoom->width(), 446 cmdZoom->move( _size.width() - cmdZoom->width(),
441 _size.height() - cmdZoom->height() ); 447 _size.height() - cmdZoom->height() );
442 if ( !bZoom ) { 448 if ( !bZoom ) {
443 drawableW = width() - 2 * frameWidth(); 449 drawableW = width() - 2 * frameWidth();
444 drawableH = height() - 2 * frameWidth(); 450 drawableH = height() - 2 * frameWidth();
445 makeMap( drawableW, drawableH ); 451 makeMap( drawableW, drawableH );
446 resizeContents( drawableW, drawableH ); 452 resizeContents( drawableW, drawableH );
447 } 453 }
448} 454}
449 455
450void ZoneMap::showZones( void ) const 456void ZoneMap::showZones( void ) const
451{ 457{
452 // go through the zones in the list and just display the values... 458 // go through the zones in the list and just display the values...
453 QListIterator<ZoneField> itZone( zones ); 459 QListIterator<ZoneField> itZone( zones );
454 for ( itZone.toFirst(); itZone.current(); ++itZone ) { 460 for ( itZone.toFirst(); itZone.current(); ++itZone ) {
455 ZoneField *pZone = itZone.current(); 461 ZoneField *pZone = itZone.current();
456 pZone->showStructure(); 462 pZone->showStructure();
457 } 463 }
458} 464}
459 465
466
467QWidget* ZoneMap::selectionWidget( QWidget *parent) {
468
469 QWidget *returnWidget = new QWidget( parent );
470
471 QVBoxLayout *layout = new QVBoxLayout( returnWidget );
472 QHBox *hBox = new QHBox( returnWidget );
473 QListView *continentView = new QListView( hBox );
474 continentView->addColumn( tr("Continent") );
475 QWhatsThis::add( continentView, tr("Select a continent/country here, then select a city") );
476 connect ( continentView, SIGNAL( clicked ( QListViewItem * ) ), this, SLOT( slotGetCities( QListViewItem * ) ) );
477
478 QStringList continentList;
479 QListIterator<ZoneField> itZone( zones );
480 for ( itZone.toFirst(); itZone.current(); ++itZone ) {
481 ZoneField *pZone = itZone.current();
482 if ( continentList.contains( pZone->country() ) == 0 ) {
483 QString name;
484 QListViewItem *item;
485 if ( !(pZone->country().length() > 24) ) {
486 name = pZone->country().left(pZone->country().length()-1 );
487 } else {
488 name = pZone->country().left( 24 );
489 }
490 item = new QListViewItem( continentView, name, pZone->country() );
491 continentList.append( pZone->country() );
492 }
493 }
494
495 cityView = new QListView( hBox );
496 cityView->addColumn( tr("City") );
497
498 layout->addWidget( hBox );
499 return returnWidget;
500}
501
502void ZoneMap::slotGetCities( QListViewItem * contItem) {
503
504 cityView->clear();
505 selectedCont = contItem->text( 1 );
506 QListIterator<ZoneField> itZone( zones );
507 for ( itZone.toFirst(); itZone.current(); ++itZone ) {
508 ZoneField *pZone = itZone.current();
509 if ( pZone->country() == contItem->text( 1 ) ) {
510 QListViewItem *item;
511 item = new QListViewItem( cityView, pZone->city() );
512 connect ( cityView, SIGNAL( clicked ( QListViewItem* ) ), this, SLOT( slotCitySelected( QListViewItem* ) ) );
513 }
514 }
515}
516
517void ZoneMap::slotCitySelected( QListViewItem *cityItem ) {
518 if ( cityItem ) {
519 emit signalTz( selectedCont, cityItem->text( 0 ) );
520 }
521}
522
460void ZoneMap::drawCities( QPainter *p ) 523void ZoneMap::drawCities( QPainter *p )
461{ 524{
462 int x, 525 int x, y, j;
463 y,
464 j;
465 // draw in the cities 526 // draw in the cities
466 // for testing only as when you put it 527 // for testing only as when you put it
467 // on the small screen it looks awful and not to mention useless 528 // on the small screen it looks awful and not to mention useless
468 p->setPen( red ); 529 p->setPen( red );
469 QListIterator<ZoneField> itZone( zones ); 530 QListIterator<ZoneField> itZone( zones );
470 for ( itZone.toFirst(), j = 0; itZone.current(); ++itZone, j++ ) { 531 for ( itZone.toFirst(), j = 0; itZone.current(); ++itZone, j++ ) {
471 ZoneField *pZone = itZone.current(); 532 ZoneField *pZone = itZone.current();
472 zoneToWin( pZone->x(), pZone->y(), x, y ); 533 zoneToWin( pZone->x(), pZone->y(), x, y );
473 if ( x > wImg ) 534 if ( x > wImg )
474 x = x - wImg; 535 x = x - wImg;
475 p->drawRect( x - iCITYOFFSET, y - iCITYOFFSET, iCITYSIZE, iCITYSIZE); 536 p->drawRect( x - iCITYOFFSET, y - iCITYOFFSET, iCITYSIZE, iCITYSIZE);
476 } 537 }
477} 538}
478 539
479static void dayNight(QImage *pImage) 540static void dayNight(QImage *pImage)
480{ 541{
481 // create a mask the functions from sun.h 542 // create a mask the functions from sun.h
482 double dJulian, 543 double dJulian,
483 dSunRad, 544 dSunRad,
484 dSunDecl, 545 dSunDecl,
485 dSunRadius, 546 dSunRadius,
486 dSunLong; 547 dSunLong;
487 int wImage = pImage->width(), 548 int wImage = pImage->width(),
488 hImage = pImage->height(), 549 hImage = pImage->height(),
489 iStart, 550 iStart,
490 iStop, 551 iStop,
491 iMid, 552 iMid,
492 relw, 553 relw,
493 i; 554 i;
494 short wtab[ wImage ]; 555 short wtab[ wImage ];
495 time_t tCurrent; 556 time_t tCurrent;
496 struct tm *pTm; 557 struct tm *pTm;
497 558
498 // get the position of the sun bassed on our current time... 559 // get the position of the sun bassed on our current time...
499 tCurrent = time( NULL ); 560 tCurrent = time( NULL );
500 pTm = gmtime( &tCurrent ); 561 pTm = gmtime( &tCurrent );
501 dJulian = jtime( pTm ); 562 dJulian = jtime( pTm );
502 sunpos( dJulian, 0, &dSunRad, &dSunDecl, &dSunRadius, &dSunLong ); 563 sunpos( dJulian, 0, &dSunRad, &dSunDecl, &dSunRadius, &dSunLong );
503 564
504 // now get the projected illumination 565 // now get the projected illumination
505 projillum( wtab, wImage, hImage, dSunDecl ); 566 projillum( wtab, wImage, hImage, dSunDecl );
506 relw = wImage - int( wImage * 0.0275 ); 567 relw = wImage - int( wImage * 0.0275 );
507 568
508 // draw the map, keeping in mind that we may go too far off the map... 569 // draw the map, keeping in mind that we may go too far off the map...
509 iMid = ( relw * ( 24*60 - pTm->tm_hour * 60 - pTm->tm_min ) ) / ( 24*60 ); 570 iMid = ( relw * ( 24*60 - pTm->tm_hour * 60 - pTm->tm_min ) ) / ( 24*60 );
510 571
511 for ( i = 0; i < hImage; i++ ) { 572 for ( i = 0; i < hImage; i++ ) {
512 if ( wtab[i] > 0 ) { 573 if ( wtab[i] > 0 ) {