summaryrefslogtreecommitdiff
path: root/core/settings/citytime/zonemap.cpp
Side-by-side diff
Diffstat (limited to 'core/settings/citytime/zonemap.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/settings/citytime/zonemap.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/core/settings/citytime/zonemap.cpp b/core/settings/citytime/zonemap.cpp
index b83da59..b6843d2 100644
--- a/core/settings/citytime/zonemap.cpp
+++ b/core/settings/citytime/zonemap.cpp
@@ -94,198 +94,198 @@ ZoneField::ZoneField( const QString& strLine )
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;
}
}
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 );
}
// now match the city...
iStart = regCity.match( strLine, iStart + iLen, &iLen );
if ( iStart >= 0 ) {
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 );
}
ZoneMap::ZoneMap( QWidget *parent, const char* name )
: QScrollView( parent, name ),
pLast( 0 ),
pRepaint( 0 ),
ox( 0 ),
oy( 0 ),
drawableW( -1 ),
drawableH( -1 ),
bZoom( FALSE ),
bIllum( TRUE ),
cursor( 0 )
{
viewport()->setFocusPolicy( StrongFocus );
// set mouse tracking so we can use the mouse move event
zones.setAutoDelete( true );
// get the map loaded
// just set the current image to point
pixCurr = new QPixmap();
QPixmap pixZoom = Resource::loadPixmap( "mag" );
cmdZoom = new QToolButton( this, "Zoom command" );
cmdZoom->setPixmap( pixZoom );
cmdZoom->setToggleButton( true );
cmdZoom->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0,
(QSizePolicy::SizeType)0,
cmdZoom->sizePolicy().hasHeightForWidth() ) );
cmdZoom->setMaximumSize( cmdZoom->sizeHint() );
// probably don't need this, but just in case...
cmdZoom->move( width() - cmdZoom->width(), height() - cmdZoom->height() );
lblCity = new QLabel( tr( "CITY" ), this, "City Label" );
lblCity->setMinimumSize( lblCity->sizeHint() );
lblCity->setFrameStyle( QFrame::Plain | QFrame::Box );
lblCity->setBackgroundColor( yellow );
lblCity->hide();
// A timer to make sure the label gets hidden
tHide = new QTimer( this, "Label Timer" );
QObject::connect( tHide, SIGNAL( timeout() ),
lblCity, SLOT( hide() ) );
QObject::connect( tHide, SIGNAL( timeout() ),
this, SLOT( slotRedraw() ) );
QTimer *tUpdate = new QTimer( this, "Update Timer" );
QObject::connect( tUpdate, SIGNAL( timeout() ),
this, SLOT( slotUpdate() ) );
QObject::connect( qApp, SIGNAL( timeChanged() ),
this, SLOT( slotUpdate() ) );
- QObject::connect( cmdZoom, SIGNAL( toggled( bool ) ),
- this, SLOT( slotZoom( bool ) ) );
- QObject::connect( &norm, SIGNAL( signalNewPoint( const QPoint& ) ),
- this, SLOT( slotFindCity( const QPoint& ) ) );
- QObject::connect( qApp, SIGNAL( clockChanged( bool ) ),
- this, SLOT( changeClock( bool ) ) );
+ QObject::connect( cmdZoom, SIGNAL( toggled(bool) ),
+ this, SLOT( slotZoom(bool) ) );
+ QObject::connect( &norm, SIGNAL( signalNewPoint(const QPoint&) ),
+ this, SLOT( slotFindCity(const QPoint&) ) );
+ QObject::connect( qApp, SIGNAL( clockChanged(bool) ),
+ this, SLOT( changeClock(bool) ) );
// update the sun's movement every 5 minutes
tUpdate->start( 5 * 60 * 1000 );
// May as well read in the timezone information too...
readZones();
}
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);
} 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();
}
}
void ZoneMap::viewportMousePressEvent( QMouseEvent* event )
{
// add the mouse event into the normalizer, and get the average,
// pass it along
slotRedraw();
norm.start();
norm.addEvent( event->pos() );
}
void ZoneMap::viewportMouseMoveEvent( QMouseEvent* event )
{
norm.addEvent( event->pos() );
}
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;
}
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;
}
}
ZoneField *ZoneMap::findCityNear( ZoneField *city, int key )
{
ZoneField *pZone;
ZoneField *pClosest = 0;
long ddist = LONG_MAX;
@@ -373,229 +373,229 @@ void ZoneMap::showCity( ZoneField *city )
pLast = city;
// we'll use city and country a couple of times, get them to save some
// time
QString strCity = pLast->city();
QString strCountry = pLast->country();
// Display the time at this location by setting the environment timezone
// getting the current time [there] and then swapping back the variable
// so no one notices...
QString strSave;
char *p = getenv( "TZ" );
if ( p ) {
strSave = p;
}
// set the timezone :)
setenv( "TZ", strCountry + strCity, true );
lblCity->setText( strCity.replace( QRegExp("_"), " ") + "\n" +
TimeString::shortTime( ampm ) );
lblCity->setMinimumSize( lblCity->sizeHint() );
// undue our damage...
unsetenv( "TZ" );
if ( p )
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;
} else {
// the default...
x += iLABELOFFSET;
}
if ( lblCity->height() > drawableH - y ) {
// 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;
} 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 * ) ) );
+ 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* ) ) );
+ 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;
// 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 ) {
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 )
{
int colors,
j;
uchar *p;
// assume that the image is similar to the one we have...
colors = pImage->numColors() / 2;
p = pImage->scanLine( row );
for ( j = start; j <= stop; j++ ) {
if ( p[j] < colors )
p[j] += colors;
}
}
void ZoneMap::makeMap( int w, int h )
{
QImage imgOrig = Resource::loadImage( strMAP );