-rw-r--r-- | core/settings/citytime/citytime.cpp | 94 | ||||
-rw-r--r-- | core/settings/citytime/citytimebase.cpp | 120 | ||||
-rw-r--r-- | core/settings/citytime/zonemap.cpp | 402 |
3 files changed, 314 insertions, 302 deletions
diff --git a/core/settings/citytime/citytime.cpp b/core/settings/citytime/citytime.cpp index 721285d..d73bda1 100644 --- a/core/settings/citytime/citytime.cpp +++ b/core/settings/citytime/citytime.cpp @@ -22,20 +22,24 @@ #include "zonemap.h" #include "citytime.h" +/* OPIE */ #include <qpe/qpeapplication.h> #include <qpe/config.h> #include <qpe/tzselect.h> #if !defined(QT_NO_COP) #include <qpe/qcopenvelope_qws.h> #endif +#include <opie2/odebug.h> +/* QT */ #include <qlabel.h> #include <qmessagebox.h> #include <qtoolbutton.h> #include <qlayout.h> +/* STD */ #include <stdlib.h> CityTime::CityTime( QWidget *parent, const char* name, WFlags fl ) @@ -45,9 +49,9 @@ CityTime::CityTime( QWidget *parent, const char* name, { Config config( "qpe" ); config.setGroup( "Time" ); bWhichClock = config.readBoolEntry( "AMPM", TRUE ); - qDebug( QString("%1").arg(bWhichClock) ); + odebug << QString("%1").arg(bWhichClock) << oendl; frmMap->changeClock( bWhichClock ); char *pEnv; pEnv = NULL; @@ -117,35 +121,35 @@ CityTime::CityTime( QWidget *parent, const char* name, CityTime::~CityTime() { if ( changed ) { - Config cfg("CityTime"); - cfg.setGroup("TimeZones"); - QListIterator<QToolButton> itCity( listCities ); - int i; - bool realTzWritten = FALSE; - for ( i = 0, itCity.toFirst(); i < CITIES; i++, ++itCity ) { - if ( !strCityTz[i].isNull() ) { - cfg.writeEntry("Zone"+QString::number(i), strCityTz[i]); - cfg.writeEntry("ZoneName"+QString::number(i), itCity.current()->text()); - if ( strCityTz[i] == strRealTz ) - realTzWritten = TRUE; - } - } - if ( realTzWritten ) { - cfg.removeEntry("Zone"+QString::number(CITIES)); - cfg.removeEntry("ZoneName"+QString::number(CITIES)); - } else { - cfg.writeEntry("Zone"+QString::number(CITIES), strRealTz); - if ( nameRealTz.isEmpty() ) { - int i = strRealTz.find( '/' ); - nameRealTz = strRealTz.mid( i+1 ); - } - cfg.writeEntry("ZoneName"+QString::number(CITIES), nameRealTz); - } - QCopEnvelope ( "QPE/System", "timeZoneListChange()" ); + Config cfg("CityTime"); + cfg.setGroup("TimeZones"); + QListIterator<QToolButton> itCity( listCities ); + int i; + bool realTzWritten = FALSE; + for ( i = 0, itCity.toFirst(); i < CITIES; i++, ++itCity ) { + if ( !strCityTz[i].isNull() ) { + cfg.writeEntry("Zone"+QString::number(i), strCityTz[i]); + cfg.writeEntry("ZoneName"+QString::number(i), itCity.current()->text()); + if ( strCityTz[i] == strRealTz ) + realTzWritten = TRUE; + } + } + if ( realTzWritten ) { + cfg.removeEntry("Zone"+QString::number(CITIES)); + cfg.removeEntry("ZoneName"+QString::number(CITIES)); + } else { + cfg.writeEntry("Zone"+QString::number(CITIES), strRealTz); + if ( nameRealTz.isEmpty() ) { + int i = strRealTz.find( '/' ); + nameRealTz = strRealTz.mid( i+1 ); + } + cfg.writeEntry("ZoneName"+QString::number(CITIES), nameRealTz); + } + QCopEnvelope ( "QPE/System", "timeZoneListChange()" ); - changed = FALSE; + changed = FALSE; } // restore the timezone, just in case we messed with it and // are destroyed at an inoppurtune moment if ( !strRealTz.isNull() ) { @@ -157,9 +161,9 @@ CityTime::~CityTime() void CityTime::timerEvent( QTimerEvent *e ) { if ( e ) - killTimer( timerId ); + killTimer( timerId ); // change the time again!! showTime(); int ms = 1000 - QTime::currentTime().msec(); timerId = startTimer( ms ); @@ -179,9 +183,9 @@ void CityTime::showTime( void ) // traverse the list... for ( i = 0, itTime.toFirst(); i < CITIES; i++, ++itTime) { if ( !strCityTz[i].isNull() ) { if ( setenv( "TZ", strCityTz[i], true ) == 0 ) { - itTime.current()->setText( TimeString::shortTime( bWhichClock ) ); + itTime.current()->setText( TimeString::shortTime( bWhichClock ) ); } else { QMessageBox::critical( this, tr( "Time Changing" ), tr( "There was a problem setting timezone %1" ) .arg( QString::number( i + 1 ) ) ); @@ -222,9 +226,9 @@ void CityTime::slotNewTz( const QString & strNewCountry, cmdTmp->setText( s.replace( QRegExp("_"), " " ) ); cmdTmp->toggle(); // we can actually break, since there is only one button // that is ever pressed! - changed = TRUE; + changed = TRUE; break; } } showTime(); @@ -240,17 +244,17 @@ void CityTime::readInTimes( void ) int i=0; nameRealTz = QString::null; QString zn; for ( ; i < CITIES ; i++ ) { - zn = cfg.readEntry("Zone"+QString::number(i), QString::null); - if ( zn.isNull() ) - break; - QString nm = cfg.readEntry("ZoneName"+QString::number(i)); - strCityTz[i] = zn; - itCity.current()->setText(nm); - if ( zn == strRealTz ) - nameRealTz = nm; - ++itCity; + zn = cfg.readEntry("Zone"+QString::number(i), QString::null); + if ( zn.isNull() ) + break; + QString nm = cfg.readEntry("ZoneName"+QString::number(i)); + strCityTz[i] = zn; + itCity.current()->setText(nm); + if ( zn == strRealTz ) + nameRealTz = nm; + ++itCity; } if ( i == 0 ) { // write in our own in a shameless self promotion and some humor QStringList list = timezoneDefaults(); @@ -262,14 +266,14 @@ void CityTime::readInTimes( void ) itCity.current()->setText( *it++ ); } } if ( nameRealTz.isEmpty() ) { - //remember the current time zone even if we don't have room - //to show it. - zn = cfg.readEntry("Zone"+QString::number(CITIES), QString::null); - if ( zn == strRealTz ) - nameRealTz = cfg.readEntry("ZoneName"+QString::number(CITIES)); - i++; + //remember the current time zone even if we don't have room + //to show it. + zn = cfg.readEntry("Zone"+QString::number(CITIES), QString::null); + if ( zn == strRealTz ) + nameRealTz = cfg.readEntry("ZoneName"+QString::number(CITIES)); + i++; } } void CityTime::changeClock( bool newClock ) diff --git a/core/settings/citytime/citytimebase.cpp b/core/settings/citytime/citytimebase.cpp index 323929b..77cb91d 100644 --- a/core/settings/citytime/citytimebase.cpp +++ b/core/settings/citytime/citytimebase.cpp @@ -2,12 +2,16 @@ // changes by Maximilian Reiss <harlekin@handhelds.org> #include "citytimebase.h" +#include "zonemap.h" + +/* OPIE */ +#include <opie2/odebug.h> +/* QT */ #include <qlabel.h> #include <qtoolbutton.h> -#include "zonemap.h" #include <qlayout.h> #include <qwhatsthis.h> @@ -18,9 +22,9 @@ CityTimeBase::CityTimeBase( QWidget* parent, const char* name, WFlags ) : QWidget( parent, name, WStyle_ContextHelp ) { if ( !name ) - setName( "CityTimeBase" ); + setName( "CityTimeBase" ); setCaption( tr( "City Time" ) ); CityTimeBaseLayout = new QVBoxLayout( this ); CityTimeBaseLayout->setSpacing( 3 ); CityTimeBaseLayout->setMargin( 0 ); @@ -340,72 +344,72 @@ CityTimeBase::~CityTimeBase() bool CityTimeBase::event( QEvent* ev ) { bool ret = QWidget::event( ev ); if ( ev->type() == QEvent::ApplicationFontChange ) { - QFont cmdCity7_font( cmdCity7->font() ); - cmdCity7_font.setBold( TRUE ); - cmdCity7->setFont( cmdCity7_font ); - QFont lblCTime9_font( lblCTime9->font() ); - lblCTime9_font.setPointSize( 10 ); - lblCTime9->setFont( lblCTime9_font ); - QFont cmdCity8_font( cmdCity8->font() ); - cmdCity8_font.setBold( TRUE ); - cmdCity8->setFont( cmdCity8_font ); - QFont cmdCity2_font( cmdCity2->font() ); - cmdCity2_font.setBold( TRUE ); - cmdCity2->setFont( cmdCity2_font ); - QFont lblCTime6_font( lblCTime6->font() ); - lblCTime6_font.setPointSize( 10 ); - lblCTime6->setFont( lblCTime6_font ); - QFont cmdCity6_font( cmdCity6->font() ); - cmdCity6_font.setBold( TRUE ); - cmdCity6->setFont( cmdCity6_font ); - QFont cmdCity4_font( cmdCity4->font() ); - cmdCity4_font.setBold( TRUE ); - cmdCity4->setFont( cmdCity4_font ); - QFont lblCTime5_font( lblCTime5->font() ); - lblCTime5_font.setPointSize( 10 ); - lblCTime5->setFont( lblCTime5_font ); - QFont lblCTime2_font( lblCTime2->font() ); - lblCTime2_font.setPointSize( 10 ); - lblCTime2->setFont( lblCTime2_font ); - QFont lblCTime1_font( lblCTime1->font() ); - lblCTime1_font.setPointSize( 10 ); - lblCTime1->setFont( lblCTime1_font ); - QFont cmdCity3_font( cmdCity3->font() ); - cmdCity3_font.setBold( TRUE ); - cmdCity3->setFont( cmdCity3_font ); - QFont lblCTime8_font( lblCTime8->font() ); - lblCTime8_font.setPointSize( 10 ); - lblCTime8->setFont( lblCTime8_font ); - QFont cmdCity1_font( cmdCity1->font() ); - cmdCity1_font.setBold( TRUE ); - cmdCity1->setFont( cmdCity1_font ); - QFont lblCTime7_font( lblCTime7->font() ); - lblCTime7_font.setPointSize( 10 ); - lblCTime7->setFont( lblCTime7_font ); - QFont lblCTime4_font( lblCTime4->font() ); - lblCTime4_font.setPointSize( 10 ); - lblCTime4->setFont( lblCTime4_font ); - QFont cmdCity5_font( cmdCity5->font() ); - cmdCity5_font.setBold( TRUE ); - cmdCity5->setFont( cmdCity5_font ); - QFont lblCTime3_font( lblCTime3->font() ); - lblCTime3_font.setPointSize( 10 ); - lblCTime3->setFont( lblCTime3_font ); - QFont cmdCity9_font( cmdCity9->font() ); - cmdCity9_font.setBold( TRUE ); - cmdCity9->setFont( cmdCity9_font ); + QFont cmdCity7_font( cmdCity7->font() ); + cmdCity7_font.setBold( TRUE ); + cmdCity7->setFont( cmdCity7_font ); + QFont lblCTime9_font( lblCTime9->font() ); + lblCTime9_font.setPointSize( 10 ); + lblCTime9->setFont( lblCTime9_font ); + QFont cmdCity8_font( cmdCity8->font() ); + cmdCity8_font.setBold( TRUE ); + cmdCity8->setFont( cmdCity8_font ); + QFont cmdCity2_font( cmdCity2->font() ); + cmdCity2_font.setBold( TRUE ); + cmdCity2->setFont( cmdCity2_font ); + QFont lblCTime6_font( lblCTime6->font() ); + lblCTime6_font.setPointSize( 10 ); + lblCTime6->setFont( lblCTime6_font ); + QFont cmdCity6_font( cmdCity6->font() ); + cmdCity6_font.setBold( TRUE ); + cmdCity6->setFont( cmdCity6_font ); + QFont cmdCity4_font( cmdCity4->font() ); + cmdCity4_font.setBold( TRUE ); + cmdCity4->setFont( cmdCity4_font ); + QFont lblCTime5_font( lblCTime5->font() ); + lblCTime5_font.setPointSize( 10 ); + lblCTime5->setFont( lblCTime5_font ); + QFont lblCTime2_font( lblCTime2->font() ); + lblCTime2_font.setPointSize( 10 ); + lblCTime2->setFont( lblCTime2_font ); + QFont lblCTime1_font( lblCTime1->font() ); + lblCTime1_font.setPointSize( 10 ); + lblCTime1->setFont( lblCTime1_font ); + QFont cmdCity3_font( cmdCity3->font() ); + cmdCity3_font.setBold( TRUE ); + cmdCity3->setFont( cmdCity3_font ); + QFont lblCTime8_font( lblCTime8->font() ); + lblCTime8_font.setPointSize( 10 ); + lblCTime8->setFont( lblCTime8_font ); + QFont cmdCity1_font( cmdCity1->font() ); + cmdCity1_font.setBold( TRUE ); + cmdCity1->setFont( cmdCity1_font ); + QFont lblCTime7_font( lblCTime7->font() ); + lblCTime7_font.setPointSize( 10 ); + lblCTime7->setFont( lblCTime7_font ); + QFont lblCTime4_font( lblCTime4->font() ); + lblCTime4_font.setPointSize( 10 ); + lblCTime4->setFont( lblCTime4_font ); + QFont cmdCity5_font( cmdCity5->font() ); + cmdCity5_font.setBold( TRUE ); + cmdCity5->setFont( cmdCity5_font ); + QFont lblCTime3_font( lblCTime3->font() ); + lblCTime3_font.setPointSize( 10 ); + lblCTime3->setFont( lblCTime3_font ); + QFont cmdCity9_font( cmdCity9->font() ); + cmdCity9_font.setBold( TRUE ); + cmdCity9->setFont( cmdCity9_font ); } return ret; } void CityTimeBase::beginNewTz() { - qWarning( "CityTimeBase::beginNewTz(): Not implemented yet!" ); + owarn << "CityTimeBase::beginNewTz(): Not implemented yet!" << oendl; } void CityTimeBase::slotNewTz(const QString &, const QString &) { - qWarning( "CityTimeBase::slotNewTz(const QString &, const QString &): Not implemented yet!" ); + owarn << "CityTimeBase::slotNewTz(const QString &, const QString &): Not implemented yet!" << oendl; } 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 @@ -22,11 +22,14 @@ #include "sun.h" #include "zonemap.h" +/* OPIE */ #include <qpe/resource.h> #include <qpe/qpeapplication.h> +#include <opie2/odebug.h> +/* QT */ #include <qfile.h> #include <qlabel.h> #include <qmessagebox.h> #include <qtextstream.h> @@ -36,8 +39,9 @@ #include <qhbox.h> #include <qlistview.h> #include <qwhatsthis.h> +/* STD */ #include <limits.h> // the map file... static const char strZONEINFO[] = "/usr/share/zoneinfo/zone.tab"; @@ -60,81 +64,81 @@ 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 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, + 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; - _y *= 60; - } else { - _y = tmp / 10000; - _y *= 60; - tmp %= 10000; - _y += tmp / 100; - _y *= 60; - tmp %= 100; - _y += tmp; - } + 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; + _y *= 60; + } else { + _y = tmp / 10000; + _y *= 60; + tmp %= 10000; + _y += tmp / 100; + _y *= 60; + tmp %= 100; + _y += tmp; + } } iStart = regCoord.match( strLine, iStart + iLen, &iLen ); if ( iStart >= 0 ) { - strTmp = strLine.mid( iStart, iLen ); - tmp = strTmp.toInt(); - if ( iLen < 8 ) { - _x = tmp / 100; - _x *= 60; - _x += tmp % 100; - _x *= 60; - } else { - _x = tmp / 10000; - _x *= 60; - tmp %= 10000; - _x += tmp / 100; - _x *= 60; - tmp %= 100; - _x += tmp; - } + strTmp = strLine.mid( iStart, iLen ); + tmp = strTmp.toInt(); + if ( iLen < 8 ) { + _x = tmp / 100; + _x *= 60; + _x += tmp % 100; + _x *= 60; + } else { + _x = tmp / 10000; + _x *= 60; + tmp %= 10000; + _x += tmp / 100; + _x *= 60; + tmp %= 100; + _x += tmp; + } } iStart = regCountry.match( strLine, 0, &iLen ); // help with the shortcoming in 2.x regexp... iStop = strLine.findRev( '/' ); if ( iStart >= 0 ) { - iLen = (iStop - iStart) + 1; - strCountry = strLine.mid( iStart, iLen ); + iLen = (iStop - iStart) + 1; + strCountry = strLine.mid( iStart, iLen ); } // now match the city... iStart = regCity.match( strLine, iStart + iLen, &iLen ); if ( iStart >= 0 ) { - strCity = strLine.mid( iStart, iLen ); + strCity = strLine.mid( iStart, iLen ); } } void ZoneField::showStructure( void ) const { - qDebug( "Country: %s", strCountry.latin1() ); - qDebug( "City: %s", strCity.latin1() ); - qDebug( "x: %d", _x ); - qDebug( "y: %d\n", _y ); + odebug << "Country: " << strCountry << "" << oendl; + odebug << "City: " << strCity << "" << oendl; + odebug << "x: " << _x << "" << oendl; + odebug << "y: " << _y << "\n" << oendl; } ZoneMap::ZoneMap( QWidget *parent, const char* name ) : QScrollView( parent, name ), @@ -206,23 +210,23 @@ ZoneMap::~ZoneMap() void ZoneMap::readZones( void ) { QFile fZone( strZONEINFO ); if ( !fZone.open( IO_ReadOnly ) ) { - QMessageBox::warning (this, - tr( "Unable to Find Timezone Info" ), - tr( "<p>Unable to find any timezone information in %1" ) - .arg( strZONEINFO )); - exit(-1); + QMessageBox::warning (this, + tr( "Unable to Find Timezone Info" ), + tr( "<p>Unable to find any timezone information in %1" ) + .arg( strZONEINFO )); + exit(-1); } else { - QTextStream tZone( &fZone ); - while ( !tZone.atEnd() ) { - QString strLine = tZone.readLine(); - // only pass on lines that aren't comments - if ( strLine[0] != '#' ) { - zones.append( new ZoneField( strLine ) ); - } - } - fZone.close(); + QTextStream tZone( &fZone ); + while ( !tZone.atEnd() ) { + QString strLine = tZone.readLine(); + // only pass on lines that aren't comments + if ( strLine[0] != '#' ) { + zones.append( new ZoneField( strLine ) ); + } + } + fZone.close(); } } void ZoneMap::viewportMousePressEvent( QMouseEvent* event ) @@ -244,44 +248,44 @@ void ZoneMap::viewportMouseReleaseEvent( QMouseEvent* ) // get the averaged points in case a timeout hasn't occurred, // more for "mouse clicks" norm.stop(); if ( pLast != NULL ) { - emit signalTz( pLast->country(), pLast->city() ); - pLast = NULL; + emit signalTz( pLast->country(), pLast->city() ); + pLast = NULL; } tHide->start( 2000, true ); } void ZoneMap::keyPressEvent( QKeyEvent *ke ) { switch ( ke->key() ) { - case Key_Left: - case Key_Right: - case Key_Up: - case Key_Down: { - tHide->stop(); - if ( !cursor ) - slotFindCity( QPoint( contentsWidth(), contentsHeight() ) / 2 ); - ZoneField *city = findCityNear( cursor, ke->key() ); - if ( city ) { - cursor = city; - int tmpx, tmpy; - zoneToWin( cursor->x(), cursor->y(), tmpx, tmpy ); - ensureVisible( tmpx, tmpy ); - showCity( cursor ); - tHide->start( 3000, true ); - } - } - break; - - case Key_Space: - case Key_Enter: - case Key_Return: - if ( cursor ) { - emit signalTz( cursor->country(), cursor->city() ); - tHide->start( 0, true ); - } - break; + case Key_Left: + case Key_Right: + case Key_Up: + case Key_Down: { + tHide->stop(); + if ( !cursor ) + slotFindCity( QPoint( contentsWidth(), contentsHeight() ) / 2 ); + ZoneField *city = findCityNear( cursor, ke->key() ); + if ( city ) { + cursor = city; + int tmpx, tmpy; + zoneToWin( cursor->x(), cursor->y(), tmpx, tmpy ); + ensureVisible( tmpx, tmpy ); + showCity( cursor ); + tHide->start( 3000, true ); + } + } + break; + + case Key_Space: + case Key_Enter: + case Key_Return: + if ( cursor ) { + emit signalTz( cursor->country(), cursor->city() ); + tHide->start( 0, true ); + } + break; } } ZoneField *ZoneMap::findCityNear( ZoneField *city, int key ) @@ -291,37 +295,37 @@ ZoneField *ZoneMap::findCityNear( ZoneField *city, int key ) long ddist = LONG_MAX; QListIterator<ZoneField> it( zones ); for (; it.current(); ++it) { - pZone = it.current(); - long dx = (pZone->x() - city->x())/100; - long dy = (pZone->y() - city->y())/100; - switch ( key ) { - case Key_Right: - case Key_Left: - if ( key == Key_Left ) - dx = -dx; - if ( dx > 0 ) { - long dist = QABS(dy)*4 + dx; - if ( dist < ddist ) { - ddist = dist; - pClosest = pZone; - } - } - break; - case Key_Down: - case Key_Up: - if ( key == Key_Down ) - dy = -dy; - if ( dy > 0 ) { - long dist = QABS(dx)*4 + dy; - if ( dist < ddist ) { - ddist = dist; - pClosest = pZone; - } - } - break; - } + pZone = it.current(); + long dx = (pZone->x() - city->x())/100; + long dy = (pZone->y() - city->y())/100; + switch ( key ) { + case Key_Right: + case Key_Left: + if ( key == Key_Left ) + dx = -dx; + if ( dx > 0 ) { + long dist = QABS(dy)*4 + dx; + if ( dist < ddist ) { + ddist = dist; + pClosest = pZone; + } + } + break; + case Key_Down: + case Key_Up: + if ( key == Key_Down ) + dy = -dy; + if ( dy > 0 ) { + long dist = QABS(dx)*4 + dy; + if ( dist < ddist ) { + ddist = dist; + pClosest = pZone; + } + } + break; + } } return pClosest; } @@ -350,22 +354,22 @@ void ZoneMap::slotFindCity( const QPoint &pos ) QListIterator<ZoneField> it( zones ); pClosest = 0; lClosest = LONG_MAX; for (; it.current(); ++it) { - pZone = it.current(); - // use the manhattenLength, a good enough of an appoximation here - lDistance = QABS( x - pZone->x() ) + QABS( y - pZone->y() ); - // first to zero wins! - if ( lDistance < lClosest ) { - lClosest = lDistance; - pClosest = pZone; - } + pZone = it.current(); + // use the manhattenLength, a good enough of an appoximation here + lDistance = QABS( x - pZone->x() ) + QABS( y - pZone->y() ); + // first to zero wins! + if ( lDistance < lClosest ) { + lClosest = lDistance; + pClosest = pZone; + } } // Okay, we found the closest city, but it might still be too far away. if ( lClosest <= iTHRESHOLD ) { - showCity( pClosest ); - cursor = pClosest; + showCity( pClosest ); + cursor = pClosest; } } void ZoneMap::showCity( ZoneField *city ) @@ -380,53 +384,53 @@ void ZoneMap::showCity( ZoneField *city ) // so no one notices... QString strSave; char *p = getenv( "TZ" ); if ( p ) { - strSave = p; + strSave = p; } // set the timezone :) setenv( "TZ", strCountry + strCity, true ); lblCity->setText( strCity.replace( QRegExp("_"), " ") + "\n" + - TimeString::shortTime( ampm ) ); + TimeString::shortTime( ampm ) ); lblCity->setMinimumSize( lblCity->sizeHint() ); // undue our damage... unsetenv( "TZ" ); if ( p ) - setenv( "TZ", strSave, true ); + setenv( "TZ", strSave, true ); // Now decide where to move the label, x & y can be reused int tmpx, tmpy, x, y; zoneToWin( pLast->x(), pLast->y(), tmpx, tmpy ); contentsToViewport(tmpx, tmpy, x, y); if ( lblCity->width() > drawableW - x ) { - // oops... try putting it on the right - x = x - lblCity->width() - iLABELOFFSET; + // oops... try putting it on the right + x = x - lblCity->width() - iLABELOFFSET; } else { - // the default... - x += iLABELOFFSET; + // the default... + x += iLABELOFFSET; } if ( lblCity->height() > drawableH - y ) { - // move it up... - y = y - lblCity->height() - iLABELOFFSET; + // move it up... + y = y - lblCity->height() - iLABELOFFSET; } else if ( y < 0 ) { - // the city is actually off the screen... - // this only happens on the a zoom when you are near the top, - // a quick workaround.. - y = iLABELOFFSET; + // the city is actually off the screen... + // this only happens on the a zoom when you are near the top, + // a quick workaround.. + y = iLABELOFFSET; } else { - // the default - y += iLABELOFFSET; + // 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 ); + int repx, + repy; + zoneToWin( pRepaint->x(), pRepaint->y(), repx, repy ); + updateContents( repx - iCITYOFFSET, repy - iCITYOFFSET, + iCITYSIZE, iCITYSIZE ); } updateContents( tmpx - iCITYOFFSET, tmpy - iCITYOFFSET, iCITYSIZE, - iCITYSIZE ); + iCITYSIZE ); pRepaint = pLast; lblCity->move( x, y ); lblCity->show(); @@ -438,22 +442,22 @@ void ZoneMap::resizeEvent( QResizeEvent *e ) 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 ); + 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(); + ZoneField *pZone = itZone.current(); + pZone->showStructure(); } } @@ -470,9 +474,9 @@ QWidget* ZoneMap::selectionWidget( QWidget *parent) { QStringList continentList; QListIterator<ZoneField> itZone( zones ); for ( itZone.toFirst(); itZone.current(); ++itZone ) { - ZoneField *pZone = itZone.current(); + ZoneField *pZone = itZone.current(); if ( continentList.contains( pZone->country() ) == 0 ) { QString name; QListViewItem *item; if ( !(pZone->country().length() > 24) ) { @@ -497,9 +501,9 @@ 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(); + 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*) ) ); @@ -521,13 +525,13 @@ void ZoneMap::drawCities( QPainter *p ) // 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); + 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) @@ -562,22 +566,22 @@ static void dayNight(QImage *pImage) // 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 ) { - iStart = iMid - wtab[i]; - iStop = iMid + wtab[i]; - if ( iStart < 0 ) { - darken( pImage, iStop, wImage + iStart, i ); - } else if ( iStop > wImage ) { - darken( pImage, iStop - wImage, iStart, i ); - } else { - darken( pImage, 0, iStart, i ); - darken( pImage, iStop, wImage, i ); - } - } else { - darken( pImage, 0, wImage, i ); - } + if ( wtab[i] > 0 ) { + iStart = iMid - wtab[i]; + iStop = iMid + wtab[i]; + if ( iStart < 0 ) { + darken( pImage, iStop, wImage + iStart, i ); + } else if ( iStop > wImage ) { + darken( pImage, iStop - wImage, iStart, i ); + } else { + darken( pImage, 0, iStart, i ); + darken( pImage, iStop, wImage, i ); + } + } else { + darken( pImage, 0, wImage, i ); + } } } static inline void darken( QImage *pImage, int start, int stop, int row ) @@ -590,22 +594,22 @@ static inline void darken( QImage *pImage, int start, int stop, int row ) colors = pImage->numColors() / 2; p = pImage->scanLine( row ); for ( j = start; j <= stop; j++ ) { - if ( p[j] < colors ) - p[j] += colors; + if ( p[j] < colors ) + p[j] += colors; } } void ZoneMap::makeMap( int w, int h ) { QImage imgOrig = Resource::loadImage( strMAP ); if ( imgOrig.isNull() ) { - QMessageBox::warning( this, - tr( "Couldn't Find Map" ), - tr( "<p>Couldn't load map: %1, exiting") + QMessageBox::warning( this, + tr( "Couldn't Find Map" ), + tr( "<p>Couldn't load map: %1, exiting") .arg( strMAP ) ); - exit(-1); + exit(-1); } // set up the color table for darkening... imgOrig = imgOrig.convertDepth( 8 ); @@ -613,17 +617,17 @@ void ZoneMap::makeMap( int w, int h ) // double the colors imgOrig.setNumColors( 2 * numColors ); // darken the new ones... for ( int i = 0; i < numColors; i++ ) { - QRgb rgb = imgOrig.color( i ); - imgOrig.setColor ( i + numColors, qRgb( 2 * qRed( rgb ) / 3, - 2 * qGreen( rgb ) / 3, 2 * qBlue( rgb ) / 3 ) ); + QRgb rgb = imgOrig.color( i ); + imgOrig.setColor ( i + numColors, qRgb( 2 * qRed( rgb ) / 3, + 2 * qGreen( rgb ) / 3, 2 * qBlue( rgb ) / 3 ) ); } // else go one with making the map... if ( bIllum ) { - // do a daylight mask - dayNight(&imgOrig); + // do a daylight mask + dayNight(&imgOrig); } // redo the width and height wImg = w; hImg = h; @@ -653,9 +657,9 @@ void ZoneMap::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) int pixmapW = pixCurr->width(), pixmapH = pixCurr->height(); if ( !bZoom && ( ( pixmapW != drawableW ) || ( pixmapH != drawableH) ) ) { - makeMap( drawableW, drawableH ); + makeMap( drawableW, drawableH ); } // taken from the scrollview example... int rowheight = pixCurr->height(); @@ -664,29 +668,29 @@ void ZoneMap::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) int colwidth = pixCurr->width(); int leftcol= cx / colwidth; int rightcol= ( cx + cw + colwidth - 1 ) / colwidth; for ( int r = toprow; r <= bottomrow; r++ ) { - int py = r * rowheight; - for ( int c = leftcol; c <= rightcol; c++ ) { - int px = c * colwidth; - p->drawPixmap( px, py, *pixCurr ); - } + int py = r * rowheight; + for ( int c = leftcol; c <= rightcol; c++ ) { + int px = c * colwidth; + p->drawPixmap( px, py, *pixCurr ); + } } // Draw that city! if ( pLast ) - drawCity( p, pLast ); + drawCity( p, pLast ); } void ZoneMap::slotZoom( bool setZoom ) { bZoom = setZoom; if ( bZoom ) { - makeMap( 2 * wImg , 2 * hImg ); - resizeContents( wImg, hImg ); + makeMap( 2 * wImg , 2 * hImg ); + resizeContents( wImg, hImg ); } else { - makeMap( drawableW, drawableH ); - resizeContents( drawableW, drawableH ); + makeMap( drawableW, drawableH ); + resizeContents( drawableW, drawableH ); } } void ZoneMap::slotIllum( bool setIllum ) @@ -710,11 +714,11 @@ void ZoneMap::slotRedraw( void ) // paint over that pesky city... int x, y; if ( pRepaint ) { - pLast = 0; - zoneToWin(pRepaint->x(), pRepaint->y(), x, y); - updateContents( x - iCITYOFFSET, y - iCITYOFFSET, iCITYSIZE, iCITYSIZE); + pLast = 0; + zoneToWin(pRepaint->x(), pRepaint->y(), x, y); + updateContents( x - iCITYOFFSET, y - iCITYOFFSET, iCITYSIZE, iCITYSIZE); pRepaint = 0; } } |