-rw-r--r-- | core/settings/citytime/opie-citytime.control | 2 | ||||
-rw-r--r-- | core/settings/citytime/zonemap.cpp | 10 |
2 files changed, 7 insertions, 5 deletions
diff --git a/core/settings/citytime/opie-citytime.control b/core/settings/citytime/opie-citytime.control index 03fa555..71ee7d0 100644 --- a/core/settings/citytime/opie-citytime.control +++ b/core/settings/citytime/opie-citytime.control | |||
@@ -1,10 +1,10 @@ | |||
1 | Package: opie-citytime | 1 | Package: opie-citytime |
2 | Files: plugins/application/libcitytime.so* bin/citytime apps/Settings/citytime.desktop pics/citytime | 2 | Files: plugins/application/libcitytime.so* bin/citytime apps/Settings/citytime.desktop pics/citytime |
3 | Priority: optional | 3 | Priority: optional |
4 | Section: opie/settings | 4 | Section: opie/settings |
5 | Maintainer: Maximilian Reiss <harlekin@handhelds.org> | 5 | Maintainer: Maximilian Reiss <harlekin@handhelds.org> |
6 | Architecture: arm | 6 | Architecture: arm |
7 | Depends: task-opie-minimal | 7 | Depends: task-opie-minimal, libopiecore2 |
8 | Description: Time-zone / world clock settings | 8 | Description: Time-zone / world clock settings |
9 | The time-zone manager for the Opie environment. | 9 | The time-zone manager for the Opie environment. |
10 | Version: $QPE_VERSION$EXTRAVERSION | 10 | Version: $QPE_VERSION$EXTRAVERSION |
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,357 +1,359 @@ | |||
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... |
47 | static const char strZONEINFO[] = "/usr/share/zoneinfo/zone.tab"; | 48 | static const char strZONEINFO[] = "/usr/share/zoneinfo/zone.tab"; |
48 | static const char strMAP[] = "citytime/simple_grid_400"; | 49 | static 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 |
52 | static const int iTHRESHOLD = 50000; | 53 | static const int iTHRESHOLD = 50000; |
53 | 54 | ||
54 | // The label offset (how far away from pointer) | 55 | // The label offset (how far away from pointer) |
55 | static const int iLABELOFFSET = 8; | 56 | static 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 |
58 | static const int iCITYSIZE = 3; | 59 | static const int iCITYSIZE = 3; |
59 | const int iCITYOFFSET = 2; | 60 | const int iCITYOFFSET = 2; |
60 | 61 | ||
61 | // the darkening function | 62 | // the darkening function |
62 | static inline void darken( QImage *pImage, int start, int stop, int row ); | 63 | static inline void darken( QImage *pImage, int start, int stop, int row ); |
63 | static void dayNight( QImage *pImage ); | 64 | static void dayNight( QImage *pImage ); |
64 | 65 | ||
65 | ZoneField::ZoneField( const QString& strLine ) | 66 | ZoneField::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 |
78 | // two chars, so just grap them and let it go... | 79 | // two chars, so just grap them and let it go... |
79 | strCountryCode = strLine.left( 2 ); | 80 | strCountryCode = strLine.left( 2 ); |
80 | iStart = regCoord.match( strLine, 0, &iLen ); | 81 | iStart = regCoord.match( strLine, 0, &iLen ); |
81 | if ( iStart >= 0 ) { | 82 | if ( iStart >= 0 ) { |
82 | strTmp = strLine.mid( iStart, iLen ); | 83 | strTmp = strLine.mid( iStart, iLen ); |
83 | tmp = strTmp.toInt(); | 84 | tmp = strTmp.toInt(); |
84 | // okay, there are two versions of the format, make a decision based on | 85 | // okay, there are two versions of the format, make a decision based on |
85 | // the size... | 86 | // the size... |
86 | // Oh BTW, we are storing everything in seconds! | 87 | // Oh BTW, we are storing everything in seconds! |
87 | if ( iLen < 7 ) { | 88 | if ( iLen < 7 ) { |
88 | _y = tmp / 100; | 89 | _y = tmp / 100; |
89 | _y *= 60; | 90 | _y *= 60; |
90 | _y += tmp % 100; | 91 | _y += tmp % 100; |
91 | _y *= 60; | 92 | _y *= 60; |
92 | } else { | 93 | } else { |
93 | _y = tmp / 10000; | 94 | _y = tmp / 10000; |
94 | _y *= 60; | 95 | _y *= 60; |
95 | tmp %= 10000; | 96 | tmp %= 10000; |
96 | _y += tmp / 100; | 97 | _y += tmp / 100; |
97 | _y *= 60; | 98 | _y *= 60; |
98 | tmp %= 100; | 99 | tmp %= 100; |
99 | _y += tmp; | 100 | _y += tmp; |
100 | } | 101 | } |
101 | } | 102 | } |
102 | iStart = regCoord.match( strLine, iStart + iLen, &iLen ); | 103 | iStart = regCoord.match( strLine, iStart + iLen, &iLen ); |
103 | if ( iStart >= 0 ) { | 104 | if ( iStart >= 0 ) { |
104 | strTmp = strLine.mid( iStart, iLen ); | 105 | strTmp = strLine.mid( iStart, iLen ); |
105 | tmp = strTmp.toInt(); | 106 | tmp = strTmp.toInt(); |
106 | if ( iLen < 8 ) { | 107 | if ( iLen < 8 ) { |
107 | _x = tmp / 100; | 108 | _x = tmp / 100; |
108 | _x *= 60; | 109 | _x *= 60; |
109 | _x += tmp % 100; | 110 | _x += tmp % 100; |
110 | _x *= 60; | 111 | _x *= 60; |
111 | } else { | 112 | } else { |
112 | _x = tmp / 10000; | 113 | _x = tmp / 10000; |
113 | _x *= 60; | 114 | _x *= 60; |
114 | tmp %= 10000; | 115 | tmp %= 10000; |
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 | ||
135 | void ZoneField::showStructure( void ) const | 136 | void 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 | ||
143 | ZoneMap::ZoneMap( QWidget *parent, const char* name ) | 144 | ZoneMap::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 | ||
206 | ZoneMap::~ZoneMap() | 208 | ZoneMap::~ZoneMap() |
207 | { | 209 | { |
208 | } | 210 | } |
209 | 211 | ||
210 | void ZoneMap::readZones( void ) | 212 | void 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 ) ) { |
214 | QMessageBox::warning (this, | 216 | QMessageBox::warning (this, |
215 | tr( "Unable to Find Timezone Info" ), | 217 | tr( "Unable to Find Timezone Info" ), |
216 | tr( "<p>Unable to find any timezone information in %1" ) | 218 | tr( "<p>Unable to find any timezone information in %1" ) |
217 | .arg( strZONEINFO )); | 219 | .arg( strZONEINFO )); |
218 | exit(-1); | 220 | exit(-1); |
219 | } else { | 221 | } else { |
220 | QTextStream tZone( &fZone ); | 222 | QTextStream tZone( &fZone ); |
221 | while ( !tZone.atEnd() ) { | 223 | while ( !tZone.atEnd() ) { |
222 | QString strLine = tZone.readLine(); | 224 | QString strLine = tZone.readLine(); |
223 | // only pass on lines that aren't comments | 225 | // only pass on lines that aren't comments |
224 | if ( strLine[0] != '#' ) { | 226 | if ( strLine[0] != '#' ) { |
225 | zones.append( new ZoneField( strLine ) ); | 227 | zones.append( new ZoneField( strLine ) ); |
226 | } | 228 | } |
227 | } | 229 | } |
228 | fZone.close(); | 230 | fZone.close(); |
229 | } | 231 | } |
230 | } | 232 | } |
231 | 233 | ||
232 | void ZoneMap::viewportMousePressEvent( QMouseEvent* event ) | 234 | void ZoneMap::viewportMousePressEvent( QMouseEvent* event ) |
233 | { | 235 | { |
234 | // add the mouse event into the normalizer, and get the average, | 236 | // add the mouse event into the normalizer, and get the average, |
235 | // pass it along | 237 | // pass it along |
236 | slotRedraw(); | 238 | slotRedraw(); |
237 | norm.start(); | 239 | norm.start(); |
238 | norm.addEvent( event->pos() ); | 240 | norm.addEvent( event->pos() ); |
239 | } | 241 | } |
240 | 242 | ||
241 | void ZoneMap::viewportMouseMoveEvent( QMouseEvent* event ) | 243 | void ZoneMap::viewportMouseMoveEvent( QMouseEvent* event ) |
242 | { | 244 | { |
243 | norm.addEvent( event->pos() ); | 245 | norm.addEvent( event->pos() ); |
244 | } | 246 | } |
245 | 247 | ||
246 | void ZoneMap::viewportMouseReleaseEvent( QMouseEvent* ) | 248 | void ZoneMap::viewportMouseReleaseEvent( QMouseEvent* ) |
247 | { | 249 | { |
248 | // get the averaged points in case a timeout hasn't occurred, | 250 | // get the averaged points in case a timeout hasn't occurred, |
249 | // more for "mouse clicks" | 251 | // more for "mouse clicks" |
250 | norm.stop(); | 252 | norm.stop(); |
251 | if ( pLast != NULL ) { | 253 | if ( pLast != NULL ) { |
252 | emit signalTz( pLast->country(), pLast->city() ); | 254 | emit signalTz( pLast->country(), pLast->city() ); |
253 | pLast = NULL; | 255 | pLast = NULL; |
254 | } | 256 | } |
255 | tHide->start( 2000, true ); | 257 | tHide->start( 2000, true ); |
256 | } | 258 | } |
257 | 259 | ||
258 | void ZoneMap::keyPressEvent( QKeyEvent *ke ) | 260 | void ZoneMap::keyPressEvent( QKeyEvent *ke ) |
259 | { | 261 | { |
260 | switch ( ke->key() ) { | 262 | switch ( ke->key() ) { |
261 | case Key_Left: | 263 | case Key_Left: |
262 | case Key_Right: | 264 | case Key_Right: |
263 | case Key_Up: | 265 | case Key_Up: |
264 | case Key_Down: { | 266 | case Key_Down: { |
265 | tHide->stop(); | 267 | tHide->stop(); |
266 | if ( !cursor ) | 268 | if ( !cursor ) |
267 | slotFindCity( QPoint( contentsWidth(), contentsHeight() ) / 2 ); | 269 | slotFindCity( QPoint( contentsWidth(), contentsHeight() ) / 2 ); |
268 | ZoneField *city = findCityNear( cursor, ke->key() ); | 270 | ZoneField *city = findCityNear( cursor, ke->key() ); |
269 | if ( city ) { | 271 | if ( city ) { |
270 | cursor = city; | 272 | cursor = city; |
271 | int tmpx, tmpy; | 273 | int tmpx, tmpy; |
272 | zoneToWin( cursor->x(), cursor->y(), tmpx, tmpy ); | 274 | zoneToWin( cursor->x(), cursor->y(), tmpx, tmpy ); |
273 | ensureVisible( tmpx, tmpy ); | 275 | ensureVisible( tmpx, tmpy ); |
274 | showCity( cursor ); | 276 | showCity( cursor ); |
275 | tHide->start( 3000, true ); | 277 | tHide->start( 3000, true ); |
276 | } | 278 | } |
277 | } | 279 | } |
278 | break; | 280 | break; |
279 | 281 | ||
280 | case Key_Space: | 282 | case Key_Space: |
281 | case Key_Enter: | 283 | case Key_Enter: |
282 | case Key_Return: | 284 | case Key_Return: |
283 | if ( cursor ) { | 285 | if ( cursor ) { |
284 | emit signalTz( cursor->country(), cursor->city() ); | 286 | emit signalTz( cursor->country(), cursor->city() ); |
285 | tHide->start( 0, true ); | 287 | tHide->start( 0, true ); |
286 | } | 288 | } |
287 | break; | 289 | break; |
288 | } | 290 | } |
289 | } | 291 | } |
290 | 292 | ||
291 | ZoneField *ZoneMap::findCityNear( ZoneField *city, int key ) | 293 | ZoneField *ZoneMap::findCityNear( ZoneField *city, int key ) |
292 | { | 294 | { |
293 | ZoneField *pZone; | 295 | ZoneField *pZone; |
294 | ZoneField *pClosest = 0; | 296 | ZoneField *pClosest = 0; |
295 | long ddist = LONG_MAX; | 297 | long ddist = LONG_MAX; |
296 | 298 | ||
297 | QListIterator<ZoneField> it( zones ); | 299 | QListIterator<ZoneField> it( zones ); |
298 | for (; it.current(); ++it) { | 300 | for (; it.current(); ++it) { |
299 | pZone = it.current(); | 301 | pZone = it.current(); |
300 | long dx = (pZone->x() - city->x())/100; | 302 | long dx = (pZone->x() - city->x())/100; |
301 | long dy = (pZone->y() - city->y())/100; | 303 | long dy = (pZone->y() - city->y())/100; |
302 | switch ( key ) { | 304 | switch ( key ) { |
303 | case Key_Right: | 305 | case Key_Right: |
304 | case Key_Left: | 306 | case Key_Left: |
305 | if ( key == Key_Left ) | 307 | if ( key == Key_Left ) |
306 | dx = -dx; | 308 | dx = -dx; |
307 | if ( dx > 0 ) { | 309 | if ( dx > 0 ) { |
308 | long dist = QABS(dy)*4 + dx; | 310 | long dist = QABS(dy)*4 + dx; |
309 | if ( dist < ddist ) { | 311 | if ( dist < ddist ) { |
310 | ddist = dist; | 312 | ddist = dist; |
311 | pClosest = pZone; | 313 | pClosest = pZone; |
312 | } | 314 | } |
313 | } | 315 | } |
314 | break; | 316 | break; |
315 | case Key_Down: | 317 | case Key_Down: |
316 | case Key_Up: | 318 | case Key_Up: |
317 | if ( key == Key_Down ) | 319 | if ( key == Key_Down ) |
318 | dy = -dy; | 320 | dy = -dy; |
319 | if ( dy > 0 ) { | 321 | if ( dy > 0 ) { |
320 | long dist = QABS(dx)*4 + dy; | 322 | long dist = QABS(dx)*4 + dy; |
321 | if ( dist < ddist ) { | 323 | if ( dist < ddist ) { |
322 | ddist = dist; | 324 | ddist = dist; |
323 | pClosest = pZone; | 325 | pClosest = pZone; |
324 | } | 326 | } |
325 | } | 327 | } |
326 | break; | 328 | break; |
327 | } | 329 | } |
328 | } | 330 | } |
329 | 331 | ||
330 | return pClosest; | 332 | return pClosest; |
331 | } | 333 | } |
332 | 334 | ||
333 | void ZoneMap::slotFindCity( const QPoint &pos ) | 335 | void ZoneMap::slotFindCity( const QPoint &pos ) |
334 | { | 336 | { |
335 | lblCity->hide(); | 337 | lblCity->hide(); |
336 | // given coordinates on the screen find the closest city and display the | 338 | // given coordinates on the screen find the closest city and display the |
337 | // label close to it | 339 | // label close to it |
338 | int tmpx, tmpy, x, y; | 340 | int tmpx, tmpy, x, y; |
339 | long lDistance, | 341 | long lDistance, |
340 | lClosest; | 342 | lClosest; |
341 | ZoneField *pZone, | 343 | ZoneField *pZone, |
342 | *pClosest; | 344 | *pClosest; |
343 | 345 | ||
344 | if ( tHide->isActive() ) { | 346 | if ( tHide->isActive() ) { |
345 | tHide->stop(); | 347 | tHide->stop(); |
346 | } | 348 | } |
347 | viewportToContents(pos.x(), pos.y(), tmpx, tmpy); | 349 | viewportToContents(pos.x(), pos.y(), tmpx, tmpy); |
348 | winToZone( tmpx, tmpy, x, y ); | 350 | winToZone( tmpx, tmpy, x, y ); |
349 | // Find city alogorithim: start out at an (near) infinite distance away and | 351 | // Find city alogorithim: start out at an (near) infinite distance away and |
350 | // then find the closest city, (similar to the Z-buffer technique, I guess) | 352 | // then find the closest city, (similar to the Z-buffer technique, I guess) |
351 | // the only problem is that this is all done with doubles, but I don't know | 353 | // the only problem is that this is all done with doubles, but I don't know |
352 | // another way to do it at the moment. Another problem is a linked list is | 354 | // another way to do it at the moment. Another problem is a linked list is |
353 | // used obviously something indexed would help | 355 | // used obviously something indexed would help |
354 | QListIterator<ZoneField> it( zones ); | 356 | QListIterator<ZoneField> it( zones ); |
355 | pClosest = 0; | 357 | pClosest = 0; |
356 | lClosest = LONG_MAX; | 358 | lClosest = LONG_MAX; |
357 | for (; it.current(); ++it) { | 359 | for (; it.current(); ++it) { |
@@ -413,316 +415,316 @@ void ZoneMap::showCity( ZoneField *city ) | |||
413 | } else if ( y < 0 ) { | 415 | } else if ( y < 0 ) { |
414 | // the city is actually off the screen... | 416 | // the city is actually off the screen... |
415 | // this only happens on the a zoom when you are near the top, | 417 | // this only happens on the a zoom when you are near the top, |
416 | // a quick workaround.. | 418 | // a quick workaround.. |
417 | y = iLABELOFFSET; | 419 | y = iLABELOFFSET; |
418 | } else { | 420 | } else { |
419 | // the default | 421 | // the default |
420 | y += iLABELOFFSET; | 422 | y += iLABELOFFSET; |
421 | } | 423 | } |
422 | 424 | ||
423 | // draw in the city and the label | 425 | // draw in the city and the label |
424 | if ( pRepaint ) { | 426 | if ( pRepaint ) { |
425 | int repx, | 427 | int repx, |
426 | repy; | 428 | repy; |
427 | zoneToWin( pRepaint->x(), pRepaint->y(), repx, repy ); | 429 | zoneToWin( pRepaint->x(), pRepaint->y(), repx, repy ); |
428 | updateContents( repx - iCITYOFFSET, repy - iCITYOFFSET, | 430 | updateContents( repx - iCITYOFFSET, repy - iCITYOFFSET, |
429 | iCITYSIZE, iCITYSIZE ); | 431 | iCITYSIZE, iCITYSIZE ); |
430 | } | 432 | } |
431 | updateContents( tmpx - iCITYOFFSET, tmpy - iCITYOFFSET, iCITYSIZE, | 433 | updateContents( tmpx - iCITYOFFSET, tmpy - iCITYOFFSET, iCITYSIZE, |
432 | iCITYSIZE ); | 434 | iCITYSIZE ); |
433 | pRepaint = pLast; | 435 | pRepaint = pLast; |
434 | 436 | ||
435 | lblCity->move( x, y ); | 437 | lblCity->move( x, y ); |
436 | lblCity->show(); | 438 | lblCity->show(); |
437 | } | 439 | } |
438 | 440 | ||
439 | void ZoneMap::resizeEvent( QResizeEvent *e ) | 441 | void ZoneMap::resizeEvent( QResizeEvent *e ) |
440 | { | 442 | { |
441 | // keep the zoom button down in the corner | 443 | // keep the zoom button down in the corner |
442 | QSize _size = e->size(); | 444 | QSize _size = e->size(); |
443 | cmdZoom->move( _size.width() - cmdZoom->width(), | 445 | cmdZoom->move( _size.width() - cmdZoom->width(), |
444 | _size.height() - cmdZoom->height() ); | 446 | _size.height() - cmdZoom->height() ); |
445 | if ( !bZoom ) { | 447 | if ( !bZoom ) { |
446 | drawableW = width() - 2 * frameWidth(); | 448 | drawableW = width() - 2 * frameWidth(); |
447 | drawableH = height() - 2 * frameWidth(); | 449 | drawableH = height() - 2 * frameWidth(); |
448 | makeMap( drawableW, drawableH ); | 450 | makeMap( drawableW, drawableH ); |
449 | resizeContents( drawableW, drawableH ); | 451 | resizeContents( drawableW, drawableH ); |
450 | } | 452 | } |
451 | } | 453 | } |
452 | 454 | ||
453 | void ZoneMap::showZones( void ) const | 455 | void ZoneMap::showZones( void ) const |
454 | { | 456 | { |
455 | // go through the zones in the list and just display the values... | 457 | // go through the zones in the list and just display the values... |
456 | QListIterator<ZoneField> itZone( zones ); | 458 | QListIterator<ZoneField> itZone( zones ); |
457 | for ( itZone.toFirst(); itZone.current(); ++itZone ) { | 459 | for ( itZone.toFirst(); itZone.current(); ++itZone ) { |
458 | ZoneField *pZone = itZone.current(); | 460 | ZoneField *pZone = itZone.current(); |
459 | pZone->showStructure(); | 461 | pZone->showStructure(); |
460 | } | 462 | } |
461 | } | 463 | } |
462 | 464 | ||
463 | 465 | ||
464 | QWidget* ZoneMap::selectionWidget( QWidget *parent) { | 466 | QWidget* ZoneMap::selectionWidget( QWidget *parent) { |
465 | 467 | ||
466 | QWidget *returnWidget = new QWidget( parent ); | 468 | QWidget *returnWidget = new QWidget( parent ); |
467 | 469 | ||
468 | QVBoxLayout *layout = new QVBoxLayout( returnWidget ); | 470 | QVBoxLayout *layout = new QVBoxLayout( returnWidget ); |
469 | QHBox *hBox = new QHBox( returnWidget ); | 471 | QHBox *hBox = new QHBox( returnWidget ); |
470 | QListView *continentView = new QListView( hBox ); | 472 | QListView *continentView = new QListView( hBox ); |
471 | continentView->addColumn( tr("Continent") ); | 473 | continentView->addColumn( tr("Continent") ); |
472 | QWhatsThis::add( continentView, tr("Select a continent/country here, then select a city") ); | 474 | QWhatsThis::add( continentView, tr("Select a continent/country here, then select a city") ); |
473 | connect ( continentView, SIGNAL( clicked(QListViewItem*) ), this, SLOT( slotGetCities(QListViewItem*) ) ); | 475 | connect ( continentView, SIGNAL( clicked(QListViewItem*) ), this, SLOT( slotGetCities(QListViewItem*) ) ); |
474 | 476 | ||
475 | QStringList continentList; | 477 | QStringList continentList; |
476 | QListIterator<ZoneField> itZone( zones ); | 478 | QListIterator<ZoneField> itZone( zones ); |
477 | for ( itZone.toFirst(); itZone.current(); ++itZone ) { | 479 | for ( itZone.toFirst(); itZone.current(); ++itZone ) { |
478 | ZoneField *pZone = itZone.current(); | 480 | ZoneField *pZone = itZone.current(); |
479 | if ( continentList.contains( pZone->country() ) == 0 ) { | 481 | if ( continentList.contains( pZone->country() ) == 0 ) { |
480 | QString name; | 482 | QString name; |
481 | QListViewItem *item; | 483 | QListViewItem *item; |
482 | if ( !(pZone->country().length() > 24) ) { | 484 | if ( !(pZone->country().length() > 24) ) { |
483 | name = pZone->country().left(pZone->country().length()-1 ); | 485 | name = pZone->country().left(pZone->country().length()-1 ); |
484 | } else { | 486 | } else { |
485 | name = pZone->country().left( 24 ); | 487 | name = pZone->country().left( 24 ); |
486 | } | 488 | } |
487 | item = new QListViewItem( continentView, name, pZone->country() ); | 489 | item = new QListViewItem( continentView, name, pZone->country() ); |
488 | continentList.append( pZone->country() ); | 490 | continentList.append( pZone->country() ); |
489 | } | 491 | } |
490 | } | 492 | } |
491 | 493 | ||
492 | cityView = new QListView( hBox ); | 494 | cityView = new QListView( hBox ); |
493 | cityView->addColumn( tr("City") ); | 495 | cityView->addColumn( tr("City") ); |
494 | 496 | ||
495 | layout->addWidget( hBox ); | 497 | layout->addWidget( hBox ); |
496 | return returnWidget; | 498 | return returnWidget; |
497 | } | 499 | } |
498 | 500 | ||
499 | void ZoneMap::slotGetCities( QListViewItem * contItem) { | 501 | void ZoneMap::slotGetCities( QListViewItem * contItem) { |
500 | 502 | ||
501 | cityView->clear(); | 503 | cityView->clear(); |
502 | selectedCont = contItem->text( 1 ); | 504 | selectedCont = contItem->text( 1 ); |
503 | QListIterator<ZoneField> itZone( zones ); | 505 | QListIterator<ZoneField> itZone( zones ); |
504 | for ( itZone.toFirst(); itZone.current(); ++itZone ) { | 506 | for ( itZone.toFirst(); itZone.current(); ++itZone ) { |
505 | ZoneField *pZone = itZone.current(); | 507 | ZoneField *pZone = itZone.current(); |
506 | if ( pZone->country() == contItem->text( 1 ) ) { | 508 | if ( pZone->country() == contItem->text( 1 ) ) { |
507 | QListViewItem *item; | 509 | QListViewItem *item; |
508 | item = new QListViewItem( cityView, pZone->city() ); | 510 | item = new QListViewItem( cityView, pZone->city() ); |
509 | connect ( cityView, SIGNAL( clicked(QListViewItem*) ), this, SLOT( slotCitySelected(QListViewItem*) ) ); | 511 | connect ( cityView, SIGNAL( clicked(QListViewItem*) ), this, SLOT( slotCitySelected(QListViewItem*) ) ); |
510 | } | 512 | } |
511 | } | 513 | } |
512 | } | 514 | } |
513 | 515 | ||
514 | void ZoneMap::slotCitySelected( QListViewItem *cityItem ) { | 516 | void ZoneMap::slotCitySelected( QListViewItem *cityItem ) { |
515 | if ( cityItem ) { | 517 | if ( cityItem ) { |
516 | emit signalTz( selectedCont, cityItem->text( 0 ) ); | 518 | emit signalTz( selectedCont, cityItem->text( 0 ) ); |
517 | } | 519 | } |
518 | } | 520 | } |
519 | 521 | ||
520 | void ZoneMap::drawCities( QPainter *p ) | 522 | void ZoneMap::drawCities( QPainter *p ) |
521 | { | 523 | { |
522 | int x, y, j; | 524 | int x, y, j; |
523 | // draw in the cities | 525 | // draw in the cities |
524 | // for testing only as when you put it | 526 | // for testing only as when you put it |
525 | // on the small screen it looks awful and not to mention useless | 527 | // on the small screen it looks awful and not to mention useless |
526 | p->setPen( red ); | 528 | p->setPen( red ); |
527 | QListIterator<ZoneField> itZone( zones ); | 529 | QListIterator<ZoneField> itZone( zones ); |
528 | for ( itZone.toFirst(), j = 0; itZone.current(); ++itZone, j++ ) { | 530 | for ( itZone.toFirst(), j = 0; itZone.current(); ++itZone, j++ ) { |
529 | ZoneField *pZone = itZone.current(); | 531 | ZoneField *pZone = itZone.current(); |
530 | zoneToWin( pZone->x(), pZone->y(), x, y ); | 532 | zoneToWin( pZone->x(), pZone->y(), x, y ); |
531 | if ( x > wImg ) | 533 | if ( x > wImg ) |
532 | x = x - wImg; | 534 | x = x - wImg; |
533 | p->drawRect( x - iCITYOFFSET, y - iCITYOFFSET, iCITYSIZE, iCITYSIZE); | 535 | p->drawRect( x - iCITYOFFSET, y - iCITYOFFSET, iCITYSIZE, iCITYSIZE); |
534 | } | 536 | } |
535 | } | 537 | } |
536 | 538 | ||
537 | static void dayNight(QImage *pImage) | 539 | static void dayNight(QImage *pImage) |
538 | { | 540 | { |
539 | // create a mask the functions from sun.h | 541 | // create a mask the functions from sun.h |
540 | double dJulian, | 542 | double dJulian, |
541 | dSunRad, | 543 | dSunRad, |
542 | dSunDecl, | 544 | dSunDecl, |
543 | dSunRadius, | 545 | dSunRadius, |
544 | dSunLong; | 546 | dSunLong; |
545 | int wImage = pImage->width(), | 547 | int wImage = pImage->width(), |
546 | hImage = pImage->height(), | 548 | hImage = pImage->height(), |
547 | iStart, | 549 | iStart, |
548 | iStop, | 550 | iStop, |
549 | iMid, | 551 | iMid, |
550 | relw, | 552 | relw, |
551 | i; | 553 | i; |
552 | short wtab[ wImage ]; | 554 | short wtab[ wImage ]; |
553 | time_t tCurrent; | 555 | time_t tCurrent; |
554 | struct tm *pTm; | 556 | struct tm *pTm; |
555 | 557 | ||
556 | // get the position of the sun bassed on our current time... | 558 | // get the position of the sun bassed on our current time... |
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 | ||
587 | static inline void darken( QImage *pImage, int start, int stop, int row ) | 589 | static 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 | ||
603 | void ZoneMap::makeMap( int w, int h ) | 605 | void 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 | ||
640 | void ZoneMap::drawCity( QPainter *p, const ZoneField *pCity ) | 642 | void 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 | ||
650 | void ZoneMap::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) | 652 | void 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 |
654 | drawableW = width() - 2 * frameWidth(); | 656 | drawableW = width() - 2 * frameWidth(); |
655 | drawableH = height() - 2 * frameWidth(); | 657 | drawableH = height() - 2 * frameWidth(); |
656 | 658 | ||
657 | int pixmapW = pixCurr->width(), | 659 | int pixmapW = pixCurr->width(), |
658 | pixmapH = pixCurr->height(); | 660 | pixmapH = pixCurr->height(); |
659 | if ( !bZoom && ( ( pixmapW != drawableW ) || | 661 | if ( !bZoom && ( ( pixmapW != drawableW ) || |
660 | ( pixmapH != drawableH) ) ) { | 662 | ( pixmapH != drawableH) ) ) { |
661 | makeMap( drawableW, drawableH ); | 663 | makeMap( drawableW, drawableH ); |
662 | } | 664 | } |
663 | 665 | ||
664 | // taken from the scrollview example... | 666 | // taken from the scrollview example... |
665 | int rowheight = pixCurr->height(); | 667 | int rowheight = pixCurr->height(); |
666 | int toprow = cy / rowheight; | 668 | int toprow = cy / rowheight; |
667 | int bottomrow = ( cy + ch + rowheight - 1 ) / rowheight; | 669 | int bottomrow = ( cy + ch + rowheight - 1 ) / rowheight; |
668 | int colwidth = pixCurr->width(); | 670 | int colwidth = pixCurr->width(); |
669 | int leftcol= cx / colwidth; | 671 | int leftcol= cx / colwidth; |
670 | int rightcol= ( cx + cw + colwidth - 1 ) / colwidth; | 672 | int rightcol= ( cx + cw + colwidth - 1 ) / colwidth; |
671 | for ( int r = toprow; r <= bottomrow; r++ ) { | 673 | for ( int r = toprow; r <= bottomrow; r++ ) { |
672 | int py = r * rowheight; | 674 | int py = r * rowheight; |
673 | for ( int c = leftcol; c <= rightcol; c++ ) { | 675 | for ( int c = leftcol; c <= rightcol; c++ ) { |
674 | int px = c * colwidth; | 676 | int px = c * colwidth; |
675 | p->drawPixmap( px, py, *pixCurr ); | 677 | p->drawPixmap( px, py, *pixCurr ); |
676 | } | 678 | } |
677 | } | 679 | } |
678 | 680 | ||
679 | // Draw that city! | 681 | // Draw that city! |
680 | if ( pLast ) | 682 | if ( pLast ) |
681 | drawCity( p, pLast ); | 683 | drawCity( p, pLast ); |
682 | } | 684 | } |
683 | 685 | ||
684 | void ZoneMap::slotZoom( bool setZoom ) | 686 | void ZoneMap::slotZoom( bool setZoom ) |
685 | { | 687 | { |
686 | bZoom = setZoom; | 688 | bZoom = setZoom; |
687 | if ( bZoom ) { | 689 | if ( bZoom ) { |
688 | makeMap( 2 * wImg , 2 * hImg ); | 690 | makeMap( 2 * wImg , 2 * hImg ); |
689 | resizeContents( wImg, hImg ); | 691 | resizeContents( wImg, hImg ); |
690 | } else { | 692 | } else { |
691 | makeMap( drawableW, drawableH ); | 693 | makeMap( drawableW, drawableH ); |
692 | resizeContents( drawableW, drawableH ); | 694 | resizeContents( drawableW, drawableH ); |
693 | } | 695 | } |
694 | } | 696 | } |
695 | 697 | ||
696 | void ZoneMap::slotIllum( bool setIllum ) | 698 | void ZoneMap::slotIllum( bool setIllum ) |
697 | { | 699 | { |
698 | bIllum = !setIllum; | 700 | bIllum = !setIllum; |
699 | // make the map... | 701 | // make the map... |
700 | makeMap( pixCurr->width(), pixCurr->height() ); | 702 | makeMap( pixCurr->width(), pixCurr->height() ); |
701 | updateContents( 0, 0, wImg, hImg ); | 703 | updateContents( 0, 0, wImg, hImg ); |
702 | } | 704 | } |
703 | 705 | ||
704 | void ZoneMap::slotUpdate( void ) | 706 | void ZoneMap::slotUpdate( void ) |
705 | { | 707 | { |
706 | // recalculate the light, most people will never see this, | 708 | // recalculate the light, most people will never see this, |
707 | // but it is good to be complete | 709 | // but it is good to be complete |
708 | makeMap ( pixCurr->width(), pixCurr->height() ); | 710 | makeMap ( pixCurr->width(), pixCurr->height() ); |
709 | updateContents( contentsX(), contentsY(), drawableW, drawableH ); | 711 | updateContents( contentsX(), contentsY(), drawableW, drawableH ); |
710 | } | 712 | } |
711 | 713 | ||
712 | void ZoneMap::slotRedraw( void ) | 714 | void ZoneMap::slotRedraw( void ) |
713 | { | 715 | { |
714 | // paint over that pesky city... | 716 | // paint over that pesky city... |
715 | int x, | 717 | int x, |
716 | y; | 718 | y; |
717 | if ( pRepaint ) { | 719 | if ( pRepaint ) { |
718 | pLast = 0; | 720 | pLast = 0; |
719 | zoneToWin(pRepaint->x(), pRepaint->y(), x, y); | 721 | zoneToWin(pRepaint->x(), pRepaint->y(), x, y); |
720 | updateContents( x - iCITYOFFSET, y - iCITYOFFSET, iCITYSIZE, iCITYSIZE); | 722 | updateContents( x - iCITYOFFSET, y - iCITYOFFSET, iCITYSIZE, iCITYSIZE); |
721 | pRepaint = 0; | 723 | pRepaint = 0; |
722 | } | 724 | } |
723 | } | 725 | } |
724 | 726 | ||
725 | void ZoneMap::changeClock( bool whichClock ) | 727 | void ZoneMap::changeClock( bool whichClock ) |
726 | { | 728 | { |
727 | ampm = whichClock; | 729 | ampm = whichClock; |
728 | } | 730 | } |