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.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/core/settings/citytime/zonemap.cpp b/core/settings/citytime/zonemap.cpp
index e4a25ef..7edc45f 100644
--- a/core/settings/citytime/zonemap.cpp
+++ b/core/settings/citytime/zonemap.cpp
@@ -1,77 +1,78 @@
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> 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/* OPIE */
27#include <qpe/resource.h>
28#include <qpe/qpeapplication.h>
29#include <opie2/odebug.h> 27#include <opie2/odebug.h>
28#include <opie2/oresource.h>
29
30#include <qpe/qpeapplication.h>
30 31
31/* QT */ 32/* QT */
32#include <qfile.h> 33#include <qfile.h>
33#include <qlabel.h> 34#include <qlabel.h>
34#include <qmessagebox.h> 35#include <qmessagebox.h>
35#include <qtextstream.h> 36#include <qtextstream.h>
36#include <qtimer.h> 37#include <qtimer.h>
37#include <qtoolbutton.h> 38#include <qtoolbutton.h>
38#include <qlayout.h> 39#include <qlayout.h>
39#include <qhbox.h> 40#include <qhbox.h>
40#include <qlistview.h> 41#include <qlistview.h>
41#include <qwhatsthis.h> 42#include <qwhatsthis.h>
42 43
43/* STD */ 44/* STD */
44#include <limits.h> 45#include <limits.h>
45 46
46// the map file... 47// the map file...
47static const char strZONEINFO[] = "/usr/share/zoneinfo/zone.tab"; 48static const char strZONEINFO[] = "/usr/share/zoneinfo/zone.tab";
48static const char strMAP[] = "citytime/simple_grid_400"; 49static const char strMAP[] = "citytime/simple_grid_400";
49 50
50// the maximum distance we'll allow the pointer to be away from a city 51// the maximum distance we'll allow the pointer to be away from a city
51// and still show the city's time 52// and still show the city's time
52static const int iTHRESHOLD = 50000; 53static const int iTHRESHOLD = 50000;
53 54
54// The label offset (how far away from pointer) 55// The label offset (how far away from pointer)
55static const int iLABELOFFSET = 8; 56static const int iLABELOFFSET = 8;
56 57
57// the size of the dot to draw, and where to start it 58// the size of the dot to draw, and where to start it
58static const int iCITYSIZE = 3; 59static const int iCITYSIZE = 3;
59const int iCITYOFFSET = 2; 60const int iCITYOFFSET = 2;
60 61
61// the darkening function 62// the darkening function
62static inline void darken( QImage *pImage, int start, int stop, int row ); 63static inline void darken( QImage *pImage, int start, int stop, int row );
63static void dayNight( QImage *pImage ); 64static void dayNight( QImage *pImage );
64 65
65ZoneField::ZoneField( const QString& strLine ) 66ZoneField::ZoneField( const QString& strLine )
66{ 67{
67 // make a bunch of RegExp's to match the data from the line 68 // make a bunch of RegExp's to match the data from the line
68 QRegExp regCoord( "[-+][0-9]+" ); // the latitude 69 QRegExp regCoord( "[-+][0-9]+" ); // the latitude
69 QRegExp regCountry( "[A-Za-z]+/" ); // the country (not good enough) 70 QRegExp regCountry( "[A-Za-z]+/" ); // the country (not good enough)
70 QRegExp regCity( "[A-Za-z_-]*" ); // the city 71 QRegExp regCity( "[A-Za-z_-]*" ); // the city
71 72
72 int iStart, 73 int iStart,
73 iStop, 74 iStop,
74 iLen, 75 iLen,
75 tmp; 76 tmp;
76 QString strTmp; 77 QString strTmp;
77 // we should be able to assume that the country code is always the first 78 // we should be able to assume that the country code is always the first
@@ -115,99 +116,100 @@ ZoneField::ZoneField( const QString& strLine )
115 _x += tmp / 100; 116 _x += tmp / 100;
116 _x *= 60; 117 _x *= 60;
117 tmp %= 100; 118 tmp %= 100;
118 _x += tmp; 119 _x += tmp;
119 } 120 }
120 } 121 }
121 iStart = regCountry.match( strLine, 0, &iLen ); 122 iStart = regCountry.match( strLine, 0, &iLen );
122 // help with the shortcoming in 2.x regexp... 123 // help with the shortcoming in 2.x regexp...
123 iStop = strLine.findRev( '/' ); 124 iStop = strLine.findRev( '/' );
124 if ( iStart >= 0 ) { 125 if ( iStart >= 0 ) {
125 iLen = (iStop - iStart) + 1; 126 iLen = (iStop - iStart) + 1;
126 strCountry = strLine.mid( iStart, iLen ); 127 strCountry = strLine.mid( iStart, iLen );
127 } 128 }
128 // now match the city... 129 // now match the city...
129 iStart = regCity.match( strLine, iStart + iLen, &iLen ); 130 iStart = regCity.match( strLine, iStart + iLen, &iLen );
130 if ( iStart >= 0 ) { 131 if ( iStart >= 0 ) {
131 strCity = strLine.mid( iStart, iLen ); 132 strCity = strLine.mid( iStart, iLen );
132 } 133 }
133} 134}
134 135
135void ZoneField::showStructure( void ) const 136void ZoneField::showStructure( void ) const
136{ 137{
137 odebug << "Country: " << strCountry << "" << oendl; 138 odebug << "Country: " << strCountry << "" << oendl;
138 odebug << "City: " << strCity << "" << oendl; 139 odebug << "City: " << strCity << "" << oendl;
139 odebug << "x: " << _x << "" << oendl; 140 odebug << "x: " << _x << "" << oendl;
140 odebug << "y: " << _y << "\n" << oendl; 141 odebug << "y: " << _y << "\n" << oendl;
141} 142}
142 143
143ZoneMap::ZoneMap( QWidget *parent, const char* name ) 144ZoneMap::ZoneMap( QWidget *parent, const char* name )
144 : QScrollView( parent, name ), 145 : QScrollView( parent, name ),
145 pLast( 0 ), 146 pLast( 0 ),
146 pRepaint( 0 ), 147 pRepaint( 0 ),
147 ox( 0 ), 148 ox( 0 ),
148 oy( 0 ), 149 oy( 0 ),
149 drawableW( -1 ), 150 drawableW( -1 ),
150 drawableH( -1 ), 151 drawableH( -1 ),
151 bZoom( FALSE ), 152 bZoom( FALSE ),
152 bIllum( TRUE ), 153 bIllum( TRUE ),
153 cursor( 0 ) 154 cursor( 0 )
154{ 155{
155 viewport()->setFocusPolicy( StrongFocus ); 156 viewport()->setFocusPolicy( StrongFocus );
156 157
157 // set mouse tracking so we can use the mouse move event 158 // set mouse tracking so we can use the mouse move event
158 zones.setAutoDelete( true ); 159 zones.setAutoDelete( true );
159 // get the map loaded 160 // get the map loaded
160 // just set the current image to point 161 // just set the current image to point
161 pixCurr = new QPixmap(); 162 pixCurr = new QPixmap();
162 163
163 QPixmap pixZoom = Resource::loadPixmap( "mag" ); 164 QPixmap pixZoom = Opie::Core::OResource::loadPixmap( "mag", Opie::Core::OResource::SmallIcon );
164 165
165 cmdZoom = new QToolButton( this, "Zoom command" ); 166 cmdZoom = new QToolButton( this, "Zoom command" );
167 cmdZoom->setUsesBigPixmap( qApp->desktop()->size().width() > 330 );
166 cmdZoom->setPixmap( pixZoom ); 168 cmdZoom->setPixmap( pixZoom );
167 cmdZoom->setToggleButton( true ); 169 cmdZoom->setToggleButton( true );
168 170
169 cmdZoom->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, 171 cmdZoom->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0,
170 (QSizePolicy::SizeType)0, 172 (QSizePolicy::SizeType)0,
171 cmdZoom->sizePolicy().hasHeightForWidth() ) ); 173 cmdZoom->sizePolicy().hasHeightForWidth() ) );
172 cmdZoom->setMaximumSize( cmdZoom->sizeHint() ); 174 cmdZoom->setMaximumSize( cmdZoom->sizeHint() );
173 // probably don't need this, but just in case... 175 // probably don't need this, but just in case...
174 cmdZoom->move( width() - cmdZoom->width(), height() - cmdZoom->height() ); 176 cmdZoom->move( width() - cmdZoom->width(), height() - cmdZoom->height() );
175 177
176 178
177 lblCity = new QLabel( tr( "CITY" ), this, "City Label" ); 179 lblCity = new QLabel( tr( "CITY" ), this, "City Label" );
178 lblCity->setMinimumSize( lblCity->sizeHint() ); 180 lblCity->setMinimumSize( lblCity->sizeHint() );
179 lblCity->setFrameStyle( QFrame::Plain | QFrame::Box ); 181 lblCity->setFrameStyle( QFrame::Plain | QFrame::Box );
180 lblCity->setBackgroundColor( yellow ); 182 lblCity->setBackgroundColor( yellow );
181 lblCity->hide(); 183 lblCity->hide();
182 184
183 // A timer to make sure the label gets hidden 185 // A timer to make sure the label gets hidden
184 tHide = new QTimer( this, "Label Timer" ); 186 tHide = new QTimer( this, "Label Timer" );
185 QObject::connect( tHide, SIGNAL( timeout() ), 187 QObject::connect( tHide, SIGNAL( timeout() ),
186 lblCity, SLOT( hide() ) ); 188 lblCity, SLOT( hide() ) );
187 QObject::connect( tHide, SIGNAL( timeout() ), 189 QObject::connect( tHide, SIGNAL( timeout() ),
188 this, SLOT( slotRedraw() ) ); 190 this, SLOT( slotRedraw() ) );
189 QTimer *tUpdate = new QTimer( this, "Update Timer" ); 191 QTimer *tUpdate = new QTimer( this, "Update Timer" );
190 QObject::connect( tUpdate, SIGNAL( timeout() ), 192 QObject::connect( tUpdate, SIGNAL( timeout() ),
191 this, SLOT( slotUpdate() ) ); 193 this, SLOT( slotUpdate() ) );
192 QObject::connect( qApp, SIGNAL( timeChanged() ), 194 QObject::connect( qApp, SIGNAL( timeChanged() ),
193 this, SLOT( slotUpdate() ) ); 195 this, SLOT( slotUpdate() ) );
194 QObject::connect( cmdZoom, SIGNAL( toggled(bool) ), 196 QObject::connect( cmdZoom, SIGNAL( toggled(bool) ),
195 this, SLOT( slotZoom(bool) ) ); 197 this, SLOT( slotZoom(bool) ) );
196 QObject::connect( &norm, SIGNAL( signalNewPoint(const QPoint&) ), 198 QObject::connect( &norm, SIGNAL( signalNewPoint(const QPoint&) ),
197 this, SLOT( slotFindCity(const QPoint&) ) ); 199 this, SLOT( slotFindCity(const QPoint&) ) );
198 QObject::connect( qApp, SIGNAL( clockChanged(bool) ), 200 QObject::connect( qApp, SIGNAL( clockChanged(bool) ),
199 this, SLOT( changeClock(bool) ) ); 201 this, SLOT( changeClock(bool) ) );
200 // update the sun's movement every 5 minutes 202 // update the sun's movement every 5 minutes
201 tUpdate->start( 5 * 60 * 1000 ); 203 tUpdate->start( 5 * 60 * 1000 );
202 // May as well read in the timezone information too... 204 // May as well read in the timezone information too...
203 readZones(); 205 readZones();
204} 206}
205 207
206ZoneMap::~ZoneMap() 208ZoneMap::~ZoneMap()
207{ 209{
208} 210}
209 211
210void ZoneMap::readZones( void ) 212void ZoneMap::readZones( void )
211{ 213{
212 QFile fZone( strZONEINFO ); 214 QFile fZone( strZONEINFO );
213 if ( !fZone.open( IO_ReadOnly ) ) { 215 if ( !fZone.open( IO_ReadOnly ) ) {
@@ -557,97 +559,97 @@ static void dayNight(QImage *pImage)
557 tCurrent = time( NULL ); 559 tCurrent = time( NULL );
558 pTm = gmtime( &tCurrent ); 560 pTm = gmtime( &tCurrent );
559 dJulian = jtime( pTm ); 561 dJulian = jtime( pTm );
560 sunpos( dJulian, 0, &dSunRad, &dSunDecl, &dSunRadius, &dSunLong ); 562 sunpos( dJulian, 0, &dSunRad, &dSunDecl, &dSunRadius, &dSunLong );
561 563
562 // now get the projected illumination 564 // now get the projected illumination
563 projillum( wtab, wImage, hImage, dSunDecl ); 565 projillum( wtab, wImage, hImage, dSunDecl );
564 relw = wImage - int( wImage * 0.0275 ); 566 relw = wImage - int( wImage * 0.0275 );
565 567
566 // draw the map, keeping in mind that we may go too far off the map... 568 // draw the map, keeping in mind that we may go too far off the map...
567 iMid = ( relw * ( 24*60 - pTm->tm_hour * 60 - pTm->tm_min ) ) / ( 24*60 ); 569 iMid = ( relw * ( 24*60 - pTm->tm_hour * 60 - pTm->tm_min ) ) / ( 24*60 );
568 570
569 for ( i = 0; i < hImage; i++ ) { 571 for ( i = 0; i < hImage; i++ ) {
570 if ( wtab[i] > 0 ) { 572 if ( wtab[i] > 0 ) {
571 iStart = iMid - wtab[i]; 573 iStart = iMid - wtab[i];
572 iStop = iMid + wtab[i]; 574 iStop = iMid + wtab[i];
573 if ( iStart < 0 ) { 575 if ( iStart < 0 ) {
574 darken( pImage, iStop, wImage + iStart, i ); 576 darken( pImage, iStop, wImage + iStart, i );
575 } else if ( iStop > wImage ) { 577 } else if ( iStop > wImage ) {
576 darken( pImage, iStop - wImage, iStart, i ); 578 darken( pImage, iStop - wImage, iStart, i );
577 } else { 579 } else {
578 darken( pImage, 0, iStart, i ); 580 darken( pImage, 0, iStart, i );
579 darken( pImage, iStop, wImage, i ); 581 darken( pImage, iStop, wImage, i );
580 } 582 }
581 } else { 583 } else {
582 darken( pImage, 0, wImage, i ); 584 darken( pImage, 0, wImage, i );
583 } 585 }
584 } 586 }
585} 587}
586 588
587static inline void darken( QImage *pImage, int start, int stop, int row ) 589static inline void darken( QImage *pImage, int start, int stop, int row )
588{ 590{
589 int colors, 591 int colors,
590 j; 592 j;
591 uchar *p; 593 uchar *p;
592 594
593 // assume that the image is similar to the one we have... 595 // assume that the image is similar to the one we have...
594 colors = pImage->numColors() / 2; 596 colors = pImage->numColors() / 2;
595 597
596 p = pImage->scanLine( row ); 598 p = pImage->scanLine( row );
597 for ( j = start; j <= stop; j++ ) { 599 for ( j = start; j <= stop; j++ ) {
598 if ( p[j] < colors ) 600 if ( p[j] < colors )
599 p[j] += colors; 601 p[j] += colors;
600 } 602 }
601} 603}
602 604
603void ZoneMap::makeMap( int w, int h ) 605void ZoneMap::makeMap( int w, int h )
604{ 606{
605 QImage imgOrig = Resource::loadImage( strMAP ); 607 QImage imgOrig = Opie::Core::OResource::loadImage( strMAP );
606 if ( imgOrig.isNull() ) { 608 if ( imgOrig.isNull() ) {
607 QMessageBox::warning( this, 609 QMessageBox::warning( this,
608 tr( "Couldn't Find Map" ), 610 tr( "Couldn't Find Map" ),
609 tr( "<p>Couldn't load map: %1, exiting") 611 tr( "<p>Couldn't load map: %1, exiting")
610 .arg( strMAP ) ); 612 .arg( strMAP ) );
611 exit(-1); 613 exit(-1);
612 } 614 }
613 615
614 // set up the color table for darkening... 616 // set up the color table for darkening...
615 imgOrig = imgOrig.convertDepth( 8 ); 617 imgOrig = imgOrig.convertDepth( 8 );
616 int numColors = imgOrig.numColors(); 618 int numColors = imgOrig.numColors();
617 // double the colors 619 // double the colors
618 imgOrig.setNumColors( 2 * numColors ); 620 imgOrig.setNumColors( 2 * numColors );
619 // darken the new ones... 621 // darken the new ones...
620 for ( int i = 0; i < numColors; i++ ) { 622 for ( int i = 0; i < numColors; i++ ) {
621 QRgb rgb = imgOrig.color( i ); 623 QRgb rgb = imgOrig.color( i );
622 imgOrig.setColor ( i + numColors, qRgb( 2 * qRed( rgb ) / 3, 624 imgOrig.setColor ( i + numColors, qRgb( 2 * qRed( rgb ) / 3,
623 2 * qGreen( rgb ) / 3, 2 * qBlue( rgb ) / 3 ) ); 625 2 * qGreen( rgb ) / 3, 2 * qBlue( rgb ) / 3 ) );
624 } 626 }
625 627
626 // else go one with making the map... 628 // else go one with making the map...
627 if ( bIllum ) { 629 if ( bIllum ) {
628 // do a daylight mask 630 // do a daylight mask
629 dayNight(&imgOrig); 631 dayNight(&imgOrig);
630 } 632 }
631 // redo the width and height 633 // redo the width and height
632 wImg = w; 634 wImg = w;
633 hImg = h; 635 hImg = h;
634 ox = ( wImg / 2 ) - int( wImg * 0.0275 ); 636 ox = ( wImg / 2 ) - int( wImg * 0.0275 );
635 oy = hImg / 2; 637 oy = hImg / 2;
636 pixCurr->convertFromImage( imgOrig.smoothScale(w, h), 638 pixCurr->convertFromImage( imgOrig.smoothScale(w, h),
637 QPixmap::ThresholdDither ); 639 QPixmap::ThresholdDither );
638} 640}
639 641
640void ZoneMap::drawCity( QPainter *p, const ZoneField *pCity ) 642void ZoneMap::drawCity( QPainter *p, const ZoneField *pCity )
641{ 643{
642 int x, 644 int x,
643 y; 645 y;
644 646
645 p->setPen( red ); 647 p->setPen( red );
646 zoneToWin( pCity->x(), pCity->y(), x, y ); 648 zoneToWin( pCity->x(), pCity->y(), x, y );
647 p->drawRect( x - iCITYOFFSET, y - iCITYOFFSET, iCITYSIZE, iCITYSIZE ); 649 p->drawRect( x - iCITYOFFSET, y - iCITYOFFSET, iCITYSIZE, iCITYSIZE );
648} 650}
649 651
650void ZoneMap::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) 652void ZoneMap::drawContents( QPainter *p, int cx, int cy, int cw, int ch )
651{ 653{
652 // if there is a need to resize, then do it... 654 // if there is a need to resize, then do it...
653 // get our drawable area 655 // get our drawable area