summaryrefslogtreecommitdiffabout
path: root/kaddressbook/geowidget.cpp
authorMichael Krelin <hacker@klever.net>2007-07-04 11:23:42 (UTC)
committer Michael Krelin <hacker@klever.net>2007-07-04 11:23:42 (UTC)
commita08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff)
tree8ee90d686081c52e7c69b5ce946e9b1a7d690001 /kaddressbook/geowidget.cpp
parent11edc920afe4f274c0964436633aa632c8288a40 (diff)
downloadkdepimpi-p1.zip
kdepimpi-p1.tar.gz
kdepimpi-p1.tar.bz2
initial public commit of qt4 portp1
Diffstat (limited to 'kaddressbook/geowidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/geowidget.cpp35
1 files changed, 21 insertions, 14 deletions
diff --git a/kaddressbook/geowidget.cpp b/kaddressbook/geowidget.cpp
index 13cd084..caff3b2 100644
--- a/kaddressbook/geowidget.cpp
+++ b/kaddressbook/geowidget.cpp
@@ -1,243 +1,250 @@
1/* 1/*
2 This file is part of KAddressBook. 2 This file is part of KAddressBook.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <kabc/geo.h> 24#include <kabc/geo.h>
25 25
26#ifndef KAB_EMBEDDED 26#ifndef KAB_EMBEDDED
27#include <kaccelmanager.h> 27#include <kaccelmanager.h>
28#else //KAB_EMBEDDED 28#else //KAB_EMBEDDED
29 29
30#include <qtextstream.h> 30#include <q3textstream.h>
31//Added by qt3to4:
32#include <QPaintEvent>
33#include <Q3GridLayout>
34#include <Q3Frame>
35#include <QMouseEvent>
31#include <kglobal.h> 36#include <kglobal.h>
32#endif //KAB_EMBEDDED 37#endif //KAB_EMBEDDED
33 38
39#include <QDesktopWidget>
40
34#include <knuminput.h> 41#include <knuminput.h>
35#include <kcombobox.h> 42#include <kcombobox.h>
36#include <kdebug.h> 43#include <kdebug.h>
37#include <kiconloader.h> 44#include <kiconloader.h>
38#include <klocale.h> 45#include <klocale.h>
39#include <kstandarddirs.h> 46#include <kstandarddirs.h>
40 47
41#include <qcheckbox.h> 48#include <qcheckbox.h>
42#include <qfile.h> 49#include <qfile.h>
43#include <qapplication.h> 50#include <qapplication.h>
44#include <qgroupbox.h> 51#include <q3groupbox.h>
45#include <qlabel.h> 52#include <qlabel.h>
46#include <qlayout.h> 53#include <qlayout.h>
47#include <qlistbox.h> 54#include <q3listbox.h>
48#include <qpainter.h> 55#include <qpainter.h>
49#include <qpixmap.h> 56#include <qpixmap.h>
50#include <qpushbutton.h> 57#include <qpushbutton.h>
51#include <qregexp.h> 58#include <qregexp.h>
52#include <qstring.h> 59#include <qstring.h>
53#include <stdlib.h> 60#include <stdlib.h>
54 61
55#include "geowidget.h" 62#include "geowidget.h"
56 63
57GeoWidget::GeoWidget( QWidget *parent, const char *name ) 64GeoWidget::GeoWidget( QWidget *parent, const char *name )
58 : QWidget( parent, name ) 65 : QWidget( parent, name )
59{ 66{
60 QLabel *label = 0; 67 QLabel *label = 0;
61 68
62 QGridLayout *topLayout = new QGridLayout( this, 4, 3 ); 69 Q3GridLayout *topLayout = new Q3GridLayout( this, 4, 3 );
63 topLayout->setMargin( KDialog::marginHint() ); 70 topLayout->setMargin( KDialog::marginHint() );
64 topLayout->setSpacing( KDialog::spacingHint() ); 71 topLayout->setSpacing( KDialog::spacingHint() );
65 72
66 label = new QLabel( this ); 73 label = new QLabel( this );
67//US ambiguous call to loadIcon. Add an additional parameter 74//US ambiguous call to loadIcon. Add an additional parameter
68//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "package_network", KIcon::Desktop ) ); 75//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "package_network", KIcon::Desktop ) );
69 label->setPixmap( KGlobal::iconLoader()->loadIcon( "package_network", KIcon::Desktop, 0 ) ); 76 label->setPixmap( KGlobal::iconLoader()->loadIcon( "package_network", KIcon::Desktop, 0 ) );
70 label->setAlignment( Qt::AlignTop ); 77 label->setAlignment( Qt::AlignTop );
71 topLayout->addMultiCellWidget( label, 0, 3, 0, 0 ); 78 topLayout->addMultiCellWidget( label, 0, 3, 0, 0 );
72 label->setAlignment( AlignCenter ); 79 label->setAlignment( Qt::AlignCenter );
73 mGeoIsValid = new QCheckBox( i18n( "Use geo data" ), this ); 80 mGeoIsValid = new QCheckBox( i18n( "Use geo data" ), this );
74 topLayout->addMultiCellWidget( mGeoIsValid, 0, 0, 1, 2 ); 81 topLayout->addMultiCellWidget( mGeoIsValid, 0, 0, 1, 2 );
75 82
76 label = new QLabel( i18n( "Latitude:" ), this ); 83 label = new QLabel( i18n( "Latitude:" ), this );
77 topLayout->addWidget( label, 1, 1 ); 84 topLayout->addWidget( label, 1, 1 );
78 85
79 mLatitudeBox = new KDoubleSpinBox( -90, 90, 1, 0, 6, this ); 86 mLatitudeBox = new KDoubleSpinBox( -90, 90, 1, 0, 6, this );
80 mLatitudeBox->setEnabled( false ); 87 mLatitudeBox->setEnabled( false );
81 mLatitudeBox->setSuffix( "" ); 88 mLatitudeBox->setSuffix( "" );
82 topLayout->addWidget( mLatitudeBox, 1, 2 ); 89 topLayout->addWidget( mLatitudeBox, 1, 2 );
83 label->setBuddy( mLatitudeBox ); 90 label->setBuddy( mLatitudeBox );
84 91
85 label = new QLabel( i18n( "Longitude:" ), this ); 92 label = new QLabel( i18n( "Longitude:" ), this );
86 topLayout->addWidget( label, 2, 1 ); 93 topLayout->addWidget( label, 2, 1 );
87 94
88 mLongitudeBox = new KDoubleSpinBox( -180, 180, 1, 0, 6, this ); 95 mLongitudeBox = new KDoubleSpinBox( -180, 180, 1, 0, 6, this );
89 mLongitudeBox->setEnabled( false ); 96 mLongitudeBox->setEnabled( false );
90 mLongitudeBox->setSuffix( "" ); 97 mLongitudeBox->setSuffix( "" );
91 topLayout->addWidget( mLongitudeBox, 2, 2 ); 98 topLayout->addWidget( mLongitudeBox, 2, 2 );
92 label->setBuddy( mLongitudeBox ); 99 label->setBuddy( mLongitudeBox );
93 100
94 mExtendedButton = new QPushButton( i18n( "Edit Geo Data..." ), this ); 101 mExtendedButton = new QPushButton( i18n( "Edit Geo Data..." ), this );
95 mExtendedButton->setEnabled( false ); 102 mExtendedButton->setEnabled( false );
96 topLayout->addMultiCellWidget( mExtendedButton, 3, 3, 1, 2 ); 103 topLayout->addMultiCellWidget( mExtendedButton, 3, 3, 1, 2 );
97 104
98 connect( mLatitudeBox, SIGNAL( valueChanged( double ) ), 105 connect( mLatitudeBox, SIGNAL( valueChanged( double ) ),
99 SIGNAL( changed() ) ); 106 SIGNAL( changed() ) );
100 connect( mLongitudeBox, SIGNAL( valueChanged( double ) ), 107 connect( mLongitudeBox, SIGNAL( valueChanged( double ) ),
101 SIGNAL( changed() ) ); 108 SIGNAL( changed() ) );
102 connect( mExtendedButton, SIGNAL( clicked() ), 109 connect( mExtendedButton, SIGNAL( clicked() ),
103 SLOT( editGeoData() ) ); 110 SLOT( editGeoData() ) );
104 111
105 connect( mGeoIsValid, SIGNAL( toggled( bool ) ), 112 connect( mGeoIsValid, SIGNAL( toggled( bool ) ),
106 mLatitudeBox, SLOT( setEnabled( bool ) ) ); 113 mLatitudeBox, SLOT( setEnabled( bool ) ) );
107 connect( mGeoIsValid, SIGNAL( toggled( bool ) ), 114 connect( mGeoIsValid, SIGNAL( toggled( bool ) ),
108 mLongitudeBox, SLOT( setEnabled( bool ) ) ); 115 mLongitudeBox, SLOT( setEnabled( bool ) ) );
109 connect( mGeoIsValid, SIGNAL( toggled( bool ) ), 116 connect( mGeoIsValid, SIGNAL( toggled( bool ) ),
110 mExtendedButton, SLOT( setEnabled( bool ) ) ); 117 mExtendedButton, SLOT( setEnabled( bool ) ) );
111 connect( mGeoIsValid, SIGNAL( toggled( bool ) ), 118 connect( mGeoIsValid, SIGNAL( toggled( bool ) ),
112 SIGNAL( changed() ) ); 119 SIGNAL( changed() ) );
113 120
114#ifndef KAB_EMBEDDED 121#ifndef KAB_EMBEDDED
115 KAcceleratorManager::manage( this ); 122 KAcceleratorManager::manage( this );
116#endif //KAB_EMBEDDED 123#endif //KAB_EMBEDDED
117} 124}
118 125
119GeoWidget::~GeoWidget() 126GeoWidget::~GeoWidget()
120{ 127{
121} 128}
122 129
123void GeoWidget::setGeo( const KABC::Geo &geo ) 130void GeoWidget::setGeo( const KABC::Geo &geo )
124{ 131{
125 if ( geo.isValid() ) { 132 if ( geo.isValid() ) {
126 mGeoIsValid->setChecked( true ); 133 mGeoIsValid->setChecked( true );
127 mLatitudeBox->setValue( geo.latitude() ); 134 mLatitudeBox->setValue( geo.latitude() );
128 mLongitudeBox->setValue( geo.longitude() ); 135 mLongitudeBox->setValue( geo.longitude() );
129 } else 136 } else
130 mGeoIsValid->setChecked( false ); 137 mGeoIsValid->setChecked( false );
131} 138}
132 139
133KABC::Geo GeoWidget::geo() const 140KABC::Geo GeoWidget::geo() const
134{ 141{
135 KABC::Geo geo; 142 KABC::Geo geo;
136 143
137 if ( mGeoIsValid->isChecked() ) { 144 if ( mGeoIsValid->isChecked() ) {
138 geo.setLatitude( mLatitudeBox->value() ); 145 geo.setLatitude( mLatitudeBox->value() );
139 geo.setLongitude( mLongitudeBox->value() ); 146 geo.setLongitude( mLongitudeBox->value() );
140 } else { 147 } else {
141 geo.setLatitude( 91 ); 148 geo.setLatitude( 91 );
142 geo.setLongitude( 181 ); 149 geo.setLongitude( 181 );
143 } 150 }
144 151
145 return geo; 152 return geo;
146} 153}
147 154
148void GeoWidget::editGeoData() 155void GeoWidget::editGeoData()
149{ 156{
150 GeoDialog dlg( this ); 157 GeoDialog dlg( this );
151 158
152 dlg.setLatitude( mLatitudeBox->value() ); 159 dlg.setLatitude( mLatitudeBox->value() );
153 dlg.setLongitude( mLongitudeBox->value() ); 160 dlg.setLongitude( mLongitudeBox->value() );
154 161
155 if ( dlg.exec() ) { 162 if ( dlg.exec() ) {
156 mLatitudeBox->setValue( dlg.latitude() ); 163 mLatitudeBox->setValue( dlg.latitude() );
157 mLongitudeBox->setValue( dlg.longitude() ); 164 mLongitudeBox->setValue( dlg.longitude() );
158 165
159 emit changed(); 166 emit changed();
160 } 167 }
161} 168}
162 169
163 170
164 171
165GeoDialog::GeoDialog( QWidget *parent, const char *name ) 172GeoDialog::GeoDialog( QWidget *parent, const char *name )
166 : KDialogBase( Plain, i18n( "Geo Data Input" ), Ok | Cancel, Ok, 173 : KDialogBase( Plain, i18n( "Geo Data Input" ), Ok | Cancel, Ok,
167 parent, name, true, true ), 174 parent, name, true, true ),
168 mUpdateSexagesimalInput( true ) 175 mUpdateSexagesimalInput( true )
169{ 176{
170 QFrame *page = plainPage(); 177 Q3Frame *page = plainPage();
171 178
172 QGridLayout *topLayout = new QGridLayout( page, 1, 1, marginHintSmall(), 179 Q3GridLayout *topLayout = new Q3GridLayout( page, 1, 1, marginHintSmall(),
173 spacingHint() ); 180 spacingHint() );
174 //topLayout->setRowStretch( 1, 1 ); 181 //topLayout->setRowStretch( 1, 1 );
175 182
176 mMapWidget = new GeoMapWidget( page ); 183 mMapWidget = new GeoMapWidget( page );
177 mCityCombo = new KComboBox( page ); 184 mCityCombo = new KComboBox( page );
178 QGroupBox *sexagesimalGroup = new QGroupBox( 0, Vertical, i18n( "Sexagesimal" ), page ); 185 Q3GroupBox *sexagesimalGroup = new Q3GroupBox( 0, Qt::Vertical, i18n( "Sexagesimal" ), page );
179 QGridLayout *sexagesimalLayout = new QGridLayout( sexagesimalGroup->layout(), 186 Q3GridLayout *sexagesimalLayout = new Q3GridLayout( sexagesimalGroup->layout(),
180 2, 5, spacingHint() ); 187 2, 5, spacingHint() );
181 QLabel *label; 188 QLabel *label;
182 if ( QApplication::desktop()->width() < 320 ) { 189 if ( QApplication::desktop()->width() < 320 ) {
183 label = new QLabel( i18n( "La." ), sexagesimalGroup ); 190 label = new QLabel( i18n( "La." ), sexagesimalGroup );
184 sexagesimalLayout->setSpacing ( spacingHintSmall() ); 191 sexagesimalLayout->setSpacing ( spacingHintSmall() );
185 sexagesimalLayout->setMargin ( marginHintSmall() ); 192 sexagesimalLayout->setMargin ( marginHintSmall() );
186 topLayout->setMargin ( 0 ); 193 topLayout->setMargin ( 0 );
187 mCityCombo->setMaximumWidth( 220 ); 194 mCityCombo->setMaximumWidth( 220 );
188 sexagesimalGroup->setMaximumWidth( 220 ); 195 sexagesimalGroup->setMaximumWidth( 220 );
189 } 196 }
190 else 197 else
191 label = new QLabel( i18n( "Latitude:" ), sexagesimalGroup ); 198 label = new QLabel( i18n( "Latitude:" ), sexagesimalGroup );
192 sexagesimalLayout->addWidget( label, 0, 0 ); 199 sexagesimalLayout->addWidget( label, 0, 0 );
193 200
194 int maxWid = 60; 201 int maxWid = 60;
195 if ( QApplication::desktop()->width() < 320 ) 202 if ( QApplication::desktop()->width() < 320 )
196 maxWid = 40; 203 maxWid = 40;
197 mLatDegrees = new QSpinBox( 0, 90, 1, sexagesimalGroup ); 204 mLatDegrees = new QSpinBox( 0, 90, 1, sexagesimalGroup );
198 mLatDegrees->setSuffix( "" ); 205 mLatDegrees->setSuffix( "" );
199 mLatDegrees->setWrapping( false ); 206 mLatDegrees->setWrapping( false );
200 sexagesimalLayout->addWidget( mLatDegrees, 0, 1 ); 207 sexagesimalLayout->addWidget( mLatDegrees, 0, 1 );
201 mLatDegrees->setMaximumWidth( maxWid ); 208 mLatDegrees->setMaximumWidth( maxWid );
202 209
203 mLatMinutes = new QSpinBox( 0, 59, 1, sexagesimalGroup ); 210 mLatMinutes = new QSpinBox( 0, 59, 1, sexagesimalGroup );
204 mLatMinutes->setSuffix( "'" ); 211 mLatMinutes->setSuffix( "'" );
205 sexagesimalLayout->addWidget( mLatMinutes, 0, 2 ); 212 sexagesimalLayout->addWidget( mLatMinutes, 0, 2 );
206 mLatMinutes->setMaximumWidth( maxWid ); 213 mLatMinutes->setMaximumWidth( maxWid );
207 214
208 mLatSeconds = new QSpinBox( 0, 59, 1, sexagesimalGroup ); 215 mLatSeconds = new QSpinBox( 0, 59, 1, sexagesimalGroup );
209 mLatSeconds->setSuffix( "\"" ); 216 mLatSeconds->setSuffix( "\"" );
210 sexagesimalLayout->addWidget( mLatSeconds, 0, 3 ); 217 sexagesimalLayout->addWidget( mLatSeconds, 0, 3 );
211 mLatSeconds->setMaximumWidth( maxWid ); 218 mLatSeconds->setMaximumWidth( maxWid );
212 219
213 mLatDirection = new KComboBox( sexagesimalGroup ); 220 mLatDirection = new KComboBox( sexagesimalGroup );
214 mLatDirection->insertItem( i18n( "North" ) ); 221 mLatDirection->insertItem( i18n( "North" ) );
215 mLatDirection->insertItem( i18n( "South" ) ); 222 mLatDirection->insertItem( i18n( "South" ) );
216 sexagesimalLayout->addWidget( mLatDirection, 0, 4 ); 223 sexagesimalLayout->addWidget( mLatDirection, 0, 4 );
217 224
218 225
219 if ( QApplication::desktop()->width() < 320 ) 226 if ( QApplication::desktop()->width() < 320 )
220 label = new QLabel( i18n( "Lo." ), sexagesimalGroup ); 227 label = new QLabel( i18n( "Lo." ), sexagesimalGroup );
221 else 228 else
222 label = new QLabel( i18n( "Longitude:" ), sexagesimalGroup ); 229 label = new QLabel( i18n( "Longitude:" ), sexagesimalGroup );
223 230
224 231
225 sexagesimalLayout->addWidget( label, 1, 0 ); 232 sexagesimalLayout->addWidget( label, 1, 0 );
226 233
227 mLongDegrees = new QSpinBox( 0, 180, 1, sexagesimalGroup ); 234 mLongDegrees = new QSpinBox( 0, 180, 1, sexagesimalGroup );
228 mLongDegrees->setSuffix( "" ); 235 mLongDegrees->setSuffix( "" );
229 sexagesimalLayout->addWidget( mLongDegrees, 1, 1 ); 236 sexagesimalLayout->addWidget( mLongDegrees, 1, 1 );
230 mLongDegrees->setMaximumWidth( maxWid ); 237 mLongDegrees->setMaximumWidth( maxWid );
231 238
232 mLongMinutes = new QSpinBox( 0, 59, 1, sexagesimalGroup ); 239 mLongMinutes = new QSpinBox( 0, 59, 1, sexagesimalGroup );
233 mLongMinutes->setSuffix( "'" ); 240 mLongMinutes->setSuffix( "'" );
234 sexagesimalLayout->addWidget( mLongMinutes, 1, 2 ); 241 sexagesimalLayout->addWidget( mLongMinutes, 1, 2 );
235 mLongMinutes->setMaximumWidth( maxWid ); 242 mLongMinutes->setMaximumWidth( maxWid );
236 243
237 mLongSeconds = new QSpinBox( 0, 59, 1, sexagesimalGroup ); 244 mLongSeconds = new QSpinBox( 0, 59, 1, sexagesimalGroup );
238 mLongSeconds->setSuffix( "\"" ); 245 mLongSeconds->setSuffix( "\"" );
239 sexagesimalLayout->addWidget( mLongSeconds, 1, 3 ); 246 sexagesimalLayout->addWidget( mLongSeconds, 1, 3 );
240 mLongSeconds->setMaximumWidth( maxWid ); 247 mLongSeconds->setMaximumWidth( maxWid );
241 248
242 mLongDirection = new KComboBox( sexagesimalGroup ); 249 mLongDirection = new KComboBox( sexagesimalGroup );
243 mLongDirection->insertItem( i18n( "East" ) ); 250 mLongDirection->insertItem( i18n( "East" ) );
@@ -368,262 +375,262 @@ void GeoDialog::updateInputs()
368 int degrees, minutes, seconds; 375 int degrees, minutes, seconds;
369 double latitude = mLatitude; 376 double latitude = mLatitude;
370 double longitude = mLongitude; 377 double longitude = mLongitude;
371 378
372 latitude *= ( mLatitude < 0 ? -1 : 1 ); 379 latitude *= ( mLatitude < 0 ? -1 : 1 );
373 longitude *= ( mLongitude < 0 ? -1 : 1 ); 380 longitude *= ( mLongitude < 0 ? -1 : 1 );
374 381
375 degrees = (int)( latitude * 1 ); 382 degrees = (int)( latitude * 1 );
376 minutes = (int)( ( latitude - degrees ) * 60 ); 383 minutes = (int)( ( latitude - degrees ) * 60 );
377 seconds = (int)( (double)( (double)latitude - (double)degrees - ( (double)minutes / (double)60 ) ) * (double)3600 ); 384 seconds = (int)( (double)( (double)latitude - (double)degrees - ( (double)minutes / (double)60 ) ) * (double)3600 );
378 385
379 mLatDegrees->setValue( degrees ); 386 mLatDegrees->setValue( degrees );
380 mLatMinutes->setValue( minutes ); 387 mLatMinutes->setValue( minutes );
381 mLatSeconds->setValue( seconds ); 388 mLatSeconds->setValue( seconds );
382 389
383 mLatDirection->setCurrentItem( mLatitude < 0 ? 1 : 0 ); 390 mLatDirection->setCurrentItem( mLatitude < 0 ? 1 : 0 );
384 391
385 degrees = (int)( longitude * 1 ); 392 degrees = (int)( longitude * 1 );
386 minutes = (int)( ( longitude - degrees ) * 60 ); 393 minutes = (int)( ( longitude - degrees ) * 60 );
387 seconds = (int)( (double)( longitude - (double)degrees - ( (double)minutes / 60 ) ) * 3600 ); 394 seconds = (int)( (double)( longitude - (double)degrees - ( (double)minutes / 60 ) ) * 3600 );
388 395
389 mLongDegrees->setValue( degrees ); 396 mLongDegrees->setValue( degrees );
390 mLongMinutes->setValue( minutes ); 397 mLongMinutes->setValue( minutes );
391 mLongSeconds->setValue( seconds ); 398 mLongSeconds->setValue( seconds );
392 mLongDirection->setCurrentItem( mLongitude < 0 ? 1 : 0 ); 399 mLongDirection->setCurrentItem( mLongitude < 0 ? 1 : 0 );
393 } 400 }
394 mUpdateSexagesimalInput = true; 401 mUpdateSexagesimalInput = true;
395 402
396 int pos = nearestCity( mLongitude, mLatitude ); 403 int pos = nearestCity( mLongitude, mLatitude );
397 if ( pos != -1 ) 404 if ( pos != -1 )
398 mCityCombo->setCurrentItem( pos + 1 ); 405 mCityCombo->setCurrentItem( pos + 1 );
399 else 406 else
400 mCityCombo->setCurrentItem( 0 ); 407 mCityCombo->setCurrentItem( 0 );
401 408
402 mCityCombo->blockSignals( false ); 409 mCityCombo->blockSignals( false );
403 mLatDegrees->blockSignals( false ); 410 mLatDegrees->blockSignals( false );
404 mLatMinutes->blockSignals( false ); 411 mLatMinutes->blockSignals( false );
405 mLatSeconds->blockSignals( false ); 412 mLatSeconds->blockSignals( false );
406 mLatDirection->blockSignals( false ); 413 mLatDirection->blockSignals( false );
407 mLongDegrees->blockSignals( false ); 414 mLongDegrees->blockSignals( false );
408 mLongMinutes->blockSignals( false ); 415 mLongMinutes->blockSignals( false );
409 mLongSeconds->blockSignals( false ); 416 mLongSeconds->blockSignals( false );
410 mLongDirection->blockSignals( false ); 417 mLongDirection->blockSignals( false );
411} 418}
412 419
413void GeoDialog::loadCityList() 420void GeoDialog::loadCityList()
414{ 421{
415 mCityCombo->clear(); 422 mCityCombo->clear();
416 mGeoDataMap.clear(); 423 mGeoDataMap.clear();
417 424
418 QString fileName ; 425 QString fileName ;
419#ifdef DESKTOP_VERSION 426#ifdef DESKTOP_VERSION
420#ifndef _WIN32_ 427#ifndef _WIN32_
421 fileName = qApp->applicationDirPath () + "/kdepim/kaddressbook/zone.tab"; 428 fileName = qApp->applicationDirPath () + "/kdepim/kaddressbook/zone.tab";
422#else 429#else
423 fileName = qApp->applicationDirPath () + "\\kdepim\\kaddressbook\\zone.tab"; 430 fileName = qApp->applicationDirPath () + "\\kdepim\\kaddressbook\\zone.tab";
424#endif 431#endif
425#else 432#else
426 fileName = getenv("QPEDIR"); 433 fileName = getenv("QPEDIR");
427 fileName += "/pics/kdepim/kaddressbook/zone.tab"; 434 fileName += "/pics/kdepim/kaddressbook/zone.tab";
428#endif 435#endif
429 436
430 QFile file( fileName); 437 QFile file( fileName);
431 438
432 if ( file.open( IO_ReadOnly ) ) { 439 if ( file.open( QIODevice::ReadOnly ) ) {
433 QTextStream s( &file ); 440 Q3TextStream s( &file );
434 441
435 QString line, country; 442 QString line, country;
436 QRegExp coord( "[+-]\\d+[+-]\\d+" ); 443 QRegExp coord( "[+-]\\d+[+-]\\d+" );
437 QRegExp name( "[^\\s]+/[^\\s]+" ); 444 QRegExp name( "[^\\s]+/[^\\s]+" );
438 int posc, posn, pos; 445 int posc, posn, pos;
439 446
440 while ( !s.eof() ) { 447 while ( !s.eof() ) {
441 line = s.readLine().stripWhiteSpace(); 448 line = s.readLine().stripWhiteSpace();
442 if ( line.isEmpty() || line[ 0 ] == '#' ) 449 if ( line.isEmpty() || line[ 0 ] == '#' )
443 continue; 450 continue;
444 451
445 country = line.left( 2 ); 452 country = line.left( 2 );
446 QString c, n; 453 QString c, n;
447#ifdef DESKTOP_VERSION 454#ifdef DESKTOP_VERSION
448 posc = coord.search( line, 0 ); 455 posc = coord.search( line, 0 );
449#else 456#else
450 posc = coord.find( line, 0 ); 457 posc = coord.find( line, 0 );
451#endif 458#endif
452 // if ( pos >= 0 ) 459 // if ( pos >= 0 )
453 //c = line.mid( pos, coord.matchedLength() ); 460 //c = line.mid( pos, coord.matchedLength() );
454 461
455#ifdef DESKTOP_VERSION 462#ifdef DESKTOP_VERSION
456 posn = name.search(line, posc); 463 posn = name.search(line, posc);
457#else 464#else
458 posn = name.find(line, posc); 465 posn = name.find(line, posc);
459#endif 466#endif
460 if ( posn > 0 ) { 467 if ( posn > 0 ) {
461 c = line.mid( posc, posn-posc ).stripWhiteSpace(); 468 c = line.mid( posc, posn-posc ).stripWhiteSpace();
462 //qDebug("*%s* ", c.latin1()); 469 //qDebug("*%s* ", c.latin1());
463 int nend = line.find(" ", posn ); 470 int nend = line.find(" ", posn );
464 if ( nend < 0 ) 471 if ( nend < 0 )
465 nend = line.length(); 472 nend = line.length();
466 n = line.mid( posn, nend-posn).stripWhiteSpace(); 473 n = line.mid( posn, nend-posn).stripWhiteSpace();
467 //n.replace( '_', " " ); 474 //n.replace( '_', " " );
468 } 475 }
469 476
470 if ( !c.isEmpty() && !n.isEmpty() ) { 477 if ( !c.isEmpty() && !n.isEmpty() ) {
471 pos = c.find( "+", 1 ); 478 pos = c.find( "+", 1 );
472 if ( pos < 0 ) 479 if ( pos < 0 )
473 pos = c.find( "-", 1 ); 480 pos = c.find( "-", 1 );
474 if ( pos > 0 ) { 481 if ( pos > 0 ) {
475 GeoData data; 482 GeoData data;
476 data.latitude = calculateCoordinate( c.left( pos ) ); 483 data.latitude = calculateCoordinate( c.left( pos ) );
477 data.longitude = calculateCoordinate( c.mid( pos ) ); 484 data.longitude = calculateCoordinate( c.mid( pos ) );
478 data.country = country; 485 data.country = country;
479 486
480 mGeoDataMap.insert( n, data ); 487 mGeoDataMap.insert( n, data );
481 } 488 }
482 } 489 }
483 } 490 }
484//US I have no mGeoDataMap.keys(). 491//US I have no mGeoDataMap.keys().
485//US QStringList items( mGeoDataMap.keys() ); 492//US QStringList items( mGeoDataMap.keys() );
486 QStringList items; 493 QStringList items;
487 494
488 QMap<QString, GeoData>::ConstIterator it; 495 QMap<QString, GeoData>::ConstIterator it;
489 for( it = mGeoDataMap.begin(); it != mGeoDataMap.end(); ++it ) 496 for( it = mGeoDataMap.begin(); it != mGeoDataMap.end(); ++it )
490 items << it.key().latin1(); 497 items << it.key().latin1();
491 498
492 items.prepend( i18n( "Undefined" ) ); 499 items.prepend( i18n( "Undefined" ) );
493 mCityCombo->insertStringList( items ); 500 mCityCombo->insertStringList( items );
494 501
495 file.close(); 502 file.close();
496 } 503 }
497} 504}
498 505
499double GeoDialog::calculateCoordinate( const QString &coordinate ) 506double GeoDialog::calculateCoordinate( const QString &coordinate )
500{ 507{
501 int neg; 508 int neg;
502 int d = 0, m = 0, s = 0; 509 int d = 0, m = 0, s = 0;
503 QString str = coordinate; 510 QString str = coordinate;
504 511
505 neg = str.left( 1 ) == "-"; 512 neg = str.left( 1 ) == "-";
506 str.remove( 0, 1 ); 513 str.remove( 0, 1 );
507 514
508 switch ( str.length() ) { 515 switch ( str.length() ) {
509 case 4: 516 case 4:
510 d = str.left( 2 ).toInt(); 517 d = str.left( 2 ).toInt();
511 m = str.mid( 2 ).toInt(); 518 m = str.mid( 2 ).toInt();
512 break; 519 break;
513 case 5: 520 case 5:
514 d = str.left( 3 ).toInt(); 521 d = str.left( 3 ).toInt();
515 m = str.mid( 3 ).toInt(); 522 m = str.mid( 3 ).toInt();
516 break; 523 break;
517 case 6: 524 case 6:
518 d = str.left( 2 ).toInt(); 525 d = str.left( 2 ).toInt();
519 m = str.mid( 2, 2 ).toInt(); 526 m = str.mid( 2, 2 ).toInt();
520 s = str.right( 2 ).toInt(); 527 s = str.right( 2 ).toInt();
521 break; 528 break;
522 case 7: 529 case 7:
523 d = str.left( 3 ).toInt(); 530 d = str.left( 3 ).toInt();
524 m = str.mid( 3, 2 ).toInt(); 531 m = str.mid( 3, 2 ).toInt();
525 s = str.right( 2 ).toInt(); 532 s = str.right( 2 ).toInt();
526 break; 533 break;
527 default: 534 default:
528 break; 535 break;
529 } 536 }
530 537
531 if ( neg ) 538 if ( neg )
532 return - ( d + m / 60.0 + s / 3600.0 ); 539 return - ( d + m / 60.0 + s / 3600.0 );
533 else 540 else
534 return d + m / 60.0 + s / 3600.0; 541 return d + m / 60.0 + s / 3600.0;
535} 542}
536 543
537int GeoDialog::nearestCity( double x, double y ) 544int GeoDialog::nearestCity( double x, double y )
538{ 545{
539 QMap<QString, GeoData>::Iterator it; 546 QMap<QString, GeoData>::Iterator it;
540 int pos = 0; 547 int pos = 0;
541 for ( it = mGeoDataMap.begin(); it != mGeoDataMap.end(); ++it, pos++ ) { 548 for ( it = mGeoDataMap.begin(); it != mGeoDataMap.end(); ++it, pos++ ) {
542 double dist = ( (*it).longitude - x ) * ( (*it).longitude - x ) + 549 double dist = ( (*it).longitude - x ) * ( (*it).longitude - x ) +
543 ( (*it).latitude - y ) * ( (*it).latitude - y ); 550 ( (*it).latitude - y ) * ( (*it).latitude - y );
544 if ( dist < 1.5 ) 551 if ( dist < 1.5 )
545 return pos; 552 return pos;
546 } 553 }
547 554
548 return -1; 555 return -1;
549} 556}
550 557
551 558
552GeoMapWidget::GeoMapWidget( QWidget *parent, const char *name ) 559GeoMapWidget::GeoMapWidget( QWidget *parent, const char *name )
553 : QWidget( parent, name ), mLatitude( 0 ), mLongitude( 0 ) 560 : QWidget( parent, name ), mLatitude( 0 ), mLongitude( 0 )
554{ 561{
555 setBackgroundMode( NoBackground ); 562 setBackgroundMode( Qt::NoBackground );
556 563
557 setFixedSize( 240, 120 ); 564 setFixedSize( 240, 120 );
558 565
559 update(); 566 update();
560} 567}
561 568
562GeoMapWidget::~GeoMapWidget() 569GeoMapWidget::~GeoMapWidget()
563{ 570{
564} 571}
565 572
566void GeoMapWidget::setLatitude( double latitude ) 573void GeoMapWidget::setLatitude( double latitude )
567{ 574{
568 mLatitude = latitude; 575 mLatitude = latitude;
569} 576}
570 577
571double GeoMapWidget::latitude()const 578double GeoMapWidget::latitude()const
572{ 579{
573 return mLatitude; 580 return mLatitude;
574} 581}
575 582
576void GeoMapWidget::setLongitude( double longitude ) 583void GeoMapWidget::setLongitude( double longitude )
577{ 584{
578 mLongitude = longitude; 585 mLongitude = longitude;
579} 586}
580 587
581double GeoMapWidget::longitude()const 588double GeoMapWidget::longitude()const
582{ 589{
583 return mLongitude; 590 return mLongitude;
584} 591}
585 592
586void GeoMapWidget::mousePressEvent( QMouseEvent *event ) 593void GeoMapWidget::mousePressEvent( QMouseEvent *event )
587{ 594{
588 double latMid = height() / 2; 595 double latMid = height() / 2;
589 double longMid = width() / 2; 596 double longMid = width() / 2;
590 597
591 double latOffset = latMid - event->y(); 598 double latOffset = latMid - event->y();
592 double longOffset = event->x() - longMid; 599 double longOffset = event->x() - longMid;
593 600
594 mLatitude = ( latOffset * 90 ) / latMid; 601 mLatitude = ( latOffset * 90 ) / latMid;
595 mLongitude = ( longOffset * 180 ) / longMid; 602 mLongitude = ( longOffset * 180 ) / longMid;
596 603
597 emit changed(); 604 emit changed();
598} 605}
599 606
600void GeoMapWidget::paintEvent( QPaintEvent* ) 607void GeoMapWidget::paintEvent( QPaintEvent* )
601{ 608{
602 uint w = width(); 609 uint w = width();
603 uint h = height(); 610 uint h = height();
604 611
605 QPixmap world = KGlobal::iconLoader()->loadIcon( "world", KIcon::Desktop, 0 ); 612 QPixmap world = KGlobal::iconLoader()->loadIcon( "world", KIcon::Desktop, 0 );
606 613
607 QPainter p; 614 QPainter p;
608 p.begin( &world, this ); 615 p.begin( &world, this );
609 616
610 p.setPen( QColor( 255, 0, 0 ) ); 617 p.setPen( QColor( 255, 0, 0 ) );
611 p.setBrush( QColor( 255, 0, 0 ) ); 618 p.setBrush( QColor( 255, 0, 0 ) );
612 619
613 double latMid = h / 2; 620 double latMid = h / 2;
614 double longMid = w / 2; 621 double longMid = w / 2;
615 622
616 double latOffset = ( mLatitude * latMid ) / 90; 623 double latOffset = ( mLatitude * latMid ) / 90;
617 double longOffset = ( mLongitude * longMid ) / 180; 624 double longOffset = ( mLongitude * longMid ) / 180;
618 625
619 int x = (int)(longMid + longOffset); 626 int x = (int)(longMid + longOffset);
620 int y = (int)(latMid - latOffset); 627 int y = (int)(latMid - latOffset);
621 p.drawEllipse( x, y, 4, 4 ); 628 p.drawEllipse( x, y, 4, 4 );
622 629
623 p.end(); 630 p.end();
624 bitBlt( this, 0, 0, &world ); 631 bitBlt( this, 0, 0, &world );
625} 632}
626 633
627#ifndef KAB_EMBEDDED 634#ifndef KAB_EMBEDDED_
628#include "geowidget.moc" 635#include "moc_geowidget.cpp"
629#endif //KAB_EMBEDDED 636#endif //KAB_EMBEDDED