summaryrefslogtreecommitdiffabout
path: root/kaddressbook/geowidget.cpp
Unidiff
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
@@ -6,91 +6,98 @@
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 );
@@ -146,58 +153,58 @@ KABC::Geo GeoWidget::geo() const
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 );
@@ -408,50 +415,50 @@ void GeoDialog::updateInputs()
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
@@ -531,49 +538,49 @@ double GeoDialog::calculateCoordinate( const QString &coordinate )
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}
@@ -603,27 +610,27 @@ void GeoMapWidget::paintEvent( QPaintEvent* )
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