Diffstat (limited to 'core/settings/citytime/zonemap.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/settings/citytime/zonemap.cpp | 67 |
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 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ +// changes by Maximilian Reiss <harlekin@handhelds.org> + #include "sun.h" #include "zonemap.h" #include <qpe/resource.h> #include <qpe/timestring.h> #include <qpe/qpeapplication.h> #include <qdatetime.h> #include <qfile.h> #include <qimage.h> #include <qlabel.h> #include <qlist.h> #include <qmessagebox.h> #include <qpixmap.h> #include <qpainter.h> #include <qregexp.h> #include <qtextstream.h> #include <qtimer.h> #include <qtoolbutton.h> +#include <qlayout.h> +#include <qhbox.h> +#include <qlistview.h> +#include <qwhatsthis.h> #include <limits.h> // the map file... static const char strZONEINFO[] = "/usr/share/zoneinfo/zone.tab"; static const char strMAP[] = "citytime/simple_grid_400"; // the maximum distance we'll allow the pointer to be away from a city // and still show the city's time static const int iTHRESHOLD = 50000; // The label offset (how far away from pointer) static const int iLABELOFFSET = 8; // the size of the dot to draw, and where to start it static const int iCITYSIZE = 3; const int iCITYOFFSET = 2; // the darkening function static inline void darken( QImage *pImage, int start, int stop, int row ); static void dayNight( QImage *pImage ); ZoneField::ZoneField( const QString& strLine ) { // make a bunch of RegExp's to match the data from the line QRegExp regCoord( "[-+][0-9]+" ); // the latitude QRegExp regCountry( "[A-Za-z]+/" ); // the country (not good enough) QRegExp regCity( "[A-Za-z_-]*" ); // the city int iStart, iStop, iLen, tmp; QString strTmp; // we should be able to assume that the country code is always the first // two chars, so just grap them and let it go... strCountryCode = strLine.left( 2 ); iStart = regCoord.match( strLine, 0, &iLen ); if ( iStart >= 0 ) { strTmp = strLine.mid( iStart, iLen ); tmp = strTmp.toInt(); // okay, there are two versions of the format, make a decision based on // the size... // Oh BTW, we are storing everything in seconds! if ( iLen < 7 ) { _y = tmp / 100; _y *= 60; _y += tmp % 100; @@ -412,101 +418,156 @@ void ZoneMap::showCity( ZoneField *city ) // this only happens on the a zoom when you are near the top, // a quick workaround.. y = iLABELOFFSET; } else { // the default y += iLABELOFFSET; } // draw in the city and the label if ( pRepaint ) { int repx, repy; zoneToWin( pRepaint->x(), pRepaint->y(), repx, repy ); updateContents( repx - iCITYOFFSET, repy - iCITYOFFSET, iCITYSIZE, iCITYSIZE ); } updateContents( tmpx - iCITYOFFSET, tmpy - iCITYOFFSET, iCITYSIZE, iCITYSIZE ); pRepaint = pLast; lblCity->move( x, y ); lblCity->show(); } void ZoneMap::resizeEvent( QResizeEvent *e ) { // keep the zoom button down in the corner QSize _size = e->size(); cmdZoom->move( _size.width() - cmdZoom->width(), _size.height() - cmdZoom->height() ); if ( !bZoom ) { drawableW = width() - 2 * frameWidth(); drawableH = height() - 2 * frameWidth(); makeMap( drawableW, drawableH ); resizeContents( drawableW, drawableH ); } } void ZoneMap::showZones( void ) const { // go through the zones in the list and just display the values... QListIterator<ZoneField> itZone( zones ); for ( itZone.toFirst(); itZone.current(); ++itZone ) { ZoneField *pZone = itZone.current(); pZone->showStructure(); } } + +QWidget* ZoneMap::selectionWidget( QWidget *parent) { + + QWidget *returnWidget = new QWidget( parent ); + + QVBoxLayout *layout = new QVBoxLayout( returnWidget ); + QHBox *hBox = new QHBox( returnWidget ); + QListView *continentView = new QListView( hBox ); + continentView->addColumn( tr("Continent") ); + QWhatsThis::add( continentView, tr("Select a continent/country here, then select a city") ); + connect ( continentView, SIGNAL( clicked ( QListViewItem * ) ), this, SLOT( slotGetCities( QListViewItem * ) ) ); + + QStringList continentList; + QListIterator<ZoneField> itZone( zones ); + for ( itZone.toFirst(); itZone.current(); ++itZone ) { + ZoneField *pZone = itZone.current(); + if ( continentList.contains( pZone->country() ) == 0 ) { + QString name; + QListViewItem *item; + if ( !(pZone->country().length() > 24) ) { + name = pZone->country().left(pZone->country().length()-1 ); + } else { + name = pZone->country().left( 24 ); + } + item = new QListViewItem( continentView, name, pZone->country() ); + continentList.append( pZone->country() ); + } + } + + cityView = new QListView( hBox ); + cityView->addColumn( tr("City") ); + + layout->addWidget( hBox ); + return returnWidget; +} + +void ZoneMap::slotGetCities( QListViewItem * contItem) { + + cityView->clear(); + selectedCont = contItem->text( 1 ); + QListIterator<ZoneField> itZone( zones ); + for ( itZone.toFirst(); itZone.current(); ++itZone ) { + ZoneField *pZone = itZone.current(); + if ( pZone->country() == contItem->text( 1 ) ) { + QListViewItem *item; + item = new QListViewItem( cityView, pZone->city() ); + connect ( cityView, SIGNAL( clicked ( QListViewItem* ) ), this, SLOT( slotCitySelected( QListViewItem* ) ) ); + } + } +} + +void ZoneMap::slotCitySelected( QListViewItem *cityItem ) { + if ( cityItem ) { + emit signalTz( selectedCont, cityItem->text( 0 ) ); + } +} + void ZoneMap::drawCities( QPainter *p ) { - int x, - y, - j; + int x, y, j; // draw in the cities // for testing only as when you put it // on the small screen it looks awful and not to mention useless p->setPen( red ); QListIterator<ZoneField> itZone( zones ); for ( itZone.toFirst(), j = 0; itZone.current(); ++itZone, j++ ) { ZoneField *pZone = itZone.current(); zoneToWin( pZone->x(), pZone->y(), x, y ); if ( x > wImg ) x = x - wImg; p->drawRect( x - iCITYOFFSET, y - iCITYOFFSET, iCITYSIZE, iCITYSIZE); } } static void dayNight(QImage *pImage) { // create a mask the functions from sun.h double dJulian, dSunRad, dSunDecl, dSunRadius, dSunLong; int wImage = pImage->width(), hImage = pImage->height(), iStart, iStop, iMid, relw, i; short wtab[ wImage ]; time_t tCurrent; struct tm *pTm; // get the position of the sun bassed on our current time... tCurrent = time( NULL ); pTm = gmtime( &tCurrent ); dJulian = jtime( pTm ); sunpos( dJulian, 0, &dSunRad, &dSunDecl, &dSunRadius, &dSunLong ); // now get the projected illumination projillum( wtab, wImage, hImage, dSunDecl ); relw = wImage - int( wImage * 0.0275 ); // draw the map, keeping in mind that we may go too far off the map... iMid = ( relw * ( 24*60 - pTm->tm_hour * 60 - pTm->tm_min ) ) / ( 24*60 ); for ( i = 0; i < hImage; i++ ) { if ( wtab[i] > 0 ) { |