1 /***************************************************************************
2 mapcanvas.cpp - K Desktop Planetarium
4 begin : Tue Apr 10 2001
5 copyright : (C) 2001 by Jason Harris
6 email : jharris@30doradus.org
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
19 #include <kstandarddirs.h>
23 #include "mapcanvas.h"
24 #include "locationdialog.h"
26 #include "kstarsdata.h"
28 MapCanvas::MapCanvas(QWidget
*parent
, const char *name
) : QWidget(parent
,name
) {
30 setBackgroundColor( QColor( BGColor
) );
31 setBackgroundMode( QWidget::NoBackground
);
32 Canvas
= new QPixmap();
33 bgImage
= new QPixmap();
34 LocationDialog
*ld
= (LocationDialog
*)topLevelWidget();
35 KStars
*ks
= (KStars
*)ld
->parent();
36 QString bgFile
= ks
->data()->stdDirs
->findResource( "data", "kstars/geomap.png" );
37 bgImage
->load( bgFile
, "PNG" );
40 MapCanvas::~MapCanvas(){
45 void MapCanvas::setGeometry( int x
, int y
, int w
, int h
) {
46 QWidget::setGeometry( x
, y
, w
, h
);
47 Canvas
->resize( w
, h
);
52 void MapCanvas::setGeometry( const QRect
&r
) {
53 QWidget::setGeometry( r
);
54 Canvas
->resize( r
.width(), r
.height() );
55 origin
.setX( r
.width()/2 );
56 origin
.setY( r
.height()/2 );
59 void MapCanvas::mousePressEvent( QMouseEvent
*e
) {
60 LocationDialog
*ld
= (LocationDialog
*)topLevelWidget();
62 //Determine Lat/Long corresponding to event press
63 int lng
= ( e
->x() - origin
.x() );
64 int lat
= ( origin
.y() - e
->y() );
66 ld
->findCitiesNear( lng
, lat
);
69 void MapCanvas::paintEvent( QPaintEvent
* ) {
71 LocationDialog
*ld
= (LocationDialog
*)topLevelWidget();
72 KStars
*ks
= (KStars
*)ld
->parent();
75 pcanvas
.begin( Canvas
);
76 // pcanvas.fillRect( 0, 0, width(), height(), QBrush( QColor( BGColor ) ) );
77 pcanvas
.drawPixmap( 0, 0, *bgImage
);
78 // pcanvas.setBrush( white );
79 pcanvas
.setPen( QPen( QColor( "SlateGrey" ) ) );
84 for ( GeoLocation
*g
=ks
->data()->geoList
.first(); g
; g
= ks
->data()->geoList
.next() ) {
85 o
.setX( int( g
->lng()->Degrees() + origin
.x() ) );
86 o
.setY( height() - int( g
->lat()->Degrees() + origin
.y() ) );
88 if ( o
.x() >= 0 && o
.x() <= width() && o
.y() >=0 && o
.y() <=height() ) {
89 pcanvas
.drawPoint( o
.x(), o
.y() );
93 //redraw the cities that appear in the filtered list, with a white pen
94 //If the list has not been filtered, skip the redraw.
95 if ( ld
->filteredList()->count() ) {
96 pcanvas
.setPen( white
);
97 for ( GeoLocation
*g
=ld
->filteredList()->first(); g
; g
= ld
->filteredList()->next() ) {
98 o
.setX( int( g
->lng()->Degrees() + origin
.x() ) );
99 o
.setY( height() - int( g
->lat()->Degrees() + origin
.y() ) );
101 if ( o
.x() >= 0 && o
.x() <= width() && o
.y() >=0 && o
.y() <=height() ) {
102 pcanvas
.drawPoint( o
.x(), o
.y() );
107 GeoLocation
*g
= ld
->selectedCity();
109 o
.setX( int( g
->lng()->Degrees() + origin
.x() ) );
110 o
.setY( height() - int( g
->lat()->Degrees() + origin
.y() ) );
112 pcanvas
.setPen( red
);
113 pcanvas
.setBrush( red
);
114 pcanvas
.drawEllipse( o
.x()-3, o
.y()-3, 6, 6 );
115 pcanvas
.moveTo( o
.x()-16, o
.y() );
116 pcanvas
.lineTo( o
.x()-8, o
.y() );
117 pcanvas
.moveTo( o
.x()+8, o
.y() );
118 pcanvas
.lineTo( o
.x()+16, o
.y() );
119 pcanvas
.moveTo( o
.x(), o
.y()-16 );
120 pcanvas
.lineTo( o
.x(), o
.y()-8 );
121 pcanvas
.moveTo( o
.x(), o
.y()+8 );
122 pcanvas
.lineTo( o
.x(), o
.y()+16 );
123 pcanvas
.setPen( white
);
124 pcanvas
.setBrush( white
);
128 bitBlt( this, 0, 0, Canvas
);
130 #include "mapcanvas.moc"