kstars
mapcanvas.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <stdlib.h>
00019 #include <kstandarddirs.h>
00020 #include <qpainter.h>
00021 #include <qpixmap.h>
00022
00023 #include "mapcanvas.h"
00024 #include "locationdialog.h"
00025 #include "kstars.h"
00026 #include "kstarsdata.h"
00027
00028 MapCanvas::MapCanvas(QWidget *parent, const char *name ) : QWidget(parent,name) {
00029 BGColor = "#33A";
00030 setBackgroundColor( QColor( BGColor ) );
00031 setBackgroundMode( QWidget::NoBackground );
00032 Canvas = new QPixmap();
00033 bgImage = new QPixmap();
00034 LocationDialog *ld = (LocationDialog *)topLevelWidget();
00035 KStars *ks = (KStars *)ld->parent();
00036 QString bgFile = ks->data()->stdDirs->findResource( "data", "kstars/geomap.png" );
00037 bgImage->load( bgFile, "PNG" );
00038 }
00039
00040 MapCanvas::~MapCanvas(){
00041 delete bgImage;
00042 delete Canvas;
00043 }
00044
00045 void MapCanvas::setGeometry( int x, int y, int w, int h ) {
00046 QWidget::setGeometry( x, y, w, h );
00047 Canvas->resize( w, h );
00048 origin.setX( w/2 );
00049 origin.setY( h/2 );
00050 }
00051
00052 void MapCanvas::setGeometry( const QRect &r ) {
00053 QWidget::setGeometry( r );
00054 Canvas->resize( r.width(), r.height() );
00055 origin.setX( r.width()/2 );
00056 origin.setY( r.height()/2 );
00057 }
00058
00059 void MapCanvas::mousePressEvent( QMouseEvent *e ) {
00060 LocationDialog *ld = (LocationDialog *)topLevelWidget();
00061
00062
00063 int lng = ( e->x() - origin.x() );
00064 int lat = ( origin.y() - e->y() );
00065
00066 ld->findCitiesNear( lng, lat );
00067 }
00068
00069 void MapCanvas::paintEvent( QPaintEvent * ) {
00070 QPainter pcanvas;
00071 LocationDialog *ld = (LocationDialog *)topLevelWidget();
00072 KStars *ks = (KStars *)ld->parent();
00073
00074
00075 pcanvas.begin( Canvas );
00076
00077 pcanvas.drawPixmap( 0, 0, *bgImage );
00078
00079 pcanvas.setPen( QPen( QColor( "SlateGrey" ) ) );
00080
00081
00082 QPoint o;
00083
00084 for ( GeoLocation *g=ks->data()->geoList.first(); g; g = ks->data()->geoList.next() ) {
00085 o.setX( int( g->lng()->Degrees() + origin.x() ) );
00086 o.setY( height() - int( g->lat()->Degrees() + origin.y() ) );
00087
00088 if ( o.x() >= 0 && o.x() <= width() && o.y() >=0 && o.y() <=height() ) {
00089 pcanvas.drawPoint( o.x(), o.y() );
00090 }
00091 }
00092
00093
00094
00095 if ( ld->filteredList()->count() ) {
00096 pcanvas.setPen( white );
00097 for ( GeoLocation *g=ld->filteredList()->first(); g; g = ld->filteredList()->next() ) {
00098 o.setX( int( g->lng()->Degrees() + origin.x() ) );
00099 o.setY( height() - int( g->lat()->Degrees() + origin.y() ) );
00100
00101 if ( o.x() >= 0 && o.x() <= width() && o.y() >=0 && o.y() <=height() ) {
00102 pcanvas.drawPoint( o.x(), o.y() );
00103 }
00104 }
00105 }
00106
00107 GeoLocation *g = ld->selectedCity();
00108 if ( g ) {
00109 o.setX( int( g->lng()->Degrees() + origin.x() ) );
00110 o.setY( height() - int( g->lat()->Degrees() + origin.y() ) );
00111
00112 pcanvas.setPen( red );
00113 pcanvas.setBrush( red );
00114 pcanvas.drawEllipse( o.x()-3, o.y()-3, 6, 6 );
00115 pcanvas.moveTo( o.x()-16, o.y() );
00116 pcanvas.lineTo( o.x()-8, o.y() );
00117 pcanvas.moveTo( o.x()+8, o.y() );
00118 pcanvas.lineTo( o.x()+16, o.y() );
00119 pcanvas.moveTo( o.x(), o.y()-16 );
00120 pcanvas.lineTo( o.x(), o.y()-8 );
00121 pcanvas.moveTo( o.x(), o.y()+8 );
00122 pcanvas.lineTo( o.x(), o.y()+16 );
00123 pcanvas.setPen( white );
00124 pcanvas.setBrush( white );
00125 }
00126
00127 pcanvas.end();
00128 bitBlt( this, 0, 0, Canvas );
00129 }
00130 #include "mapcanvas.moc"