• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • widgets
mapcanvas.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  mapcanvas.cpp - K Desktop Planetarium
3  -------------------
4  begin : Tue Apr 10 2001
5  copyright : (C) 2001 by Jason Harris
6  email : jharris@30doradus.org
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
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. *
15  * *
16  ***************************************************************************/
17 
18 #include "mapcanvas.h"
19 #include <cstdlib>
20 
21 #include <QPainter>
22 #include <QPixmap>
23 #include <QMouseEvent>
24 #include <QPaintEvent>
25 
26 #include <kstandarddirs.h>
27 
28 #include "dialogs/locationdialog.h"
29 #include "kstars.h"
30 #include "kstarsdata.h"
31 
32 MapCanvas::MapCanvas( QWidget *parent ) :
33  QFrame( parent ),
34  ld(0)
35 {
36  setAutoFillBackground( false );
37 
38  QString bgFile = KStandardDirs::locate( "data", "kstars/geomap.png" );
39  bgImage = new QPixmap( bgFile );
40 
41  origin.setX( bgImage->width()/2 );
42  origin.setY( bgImage->height()/2 );
43 }
44 
45 MapCanvas::~MapCanvas(){
46  delete bgImage;
47 }
48 
49 void MapCanvas::setGeometry( int x, int y, int w, int h ) {
50  QWidget::setGeometry( x, y, w, h );
51  origin.setX( w/2 );
52  origin.setY( h/2 );
53 }
54 
55 void MapCanvas::setGeometry( const QRect &r ) {
56  QWidget::setGeometry( r );
57  origin.setX( r.width()/2 );
58  origin.setY( r.height()/2 );
59 }
60 
61 void MapCanvas::mousePressEvent( QMouseEvent *e ) {
62  //Determine Lat/Long corresponding to event press
63  int lng = ( e->x() - origin.x() );
64  int lat = ( origin.y() - e->y() );
65 
66  if( ld )
67  ld->findCitiesNear( lng, lat );
68 }
69 
70 void MapCanvas::paintEvent( QPaintEvent * ) {
71  QPainter p;
72 
73  //prepare the canvas
74  p.begin( this );
75  p.drawPixmap( 0, 0, bgImage->scaled( size() ) );
76  p.setPen( QPen( QColor( "SlateGrey" ) ) );
77 
78  //Draw cities
79  QPoint o;
80  foreach ( GeoLocation *g, KStarsData::Instance()->getGeoList() ) {
81  o.setX( int( g->lng()->Degrees() + origin.x() ) );
82  o.setY( height() - int( g->lat()->Degrees() + origin.y() ) );
83 
84  if ( o.x() >= 0 && o.x() <= width() && o.y() >=0 && o.y() <=height() ) {
85  p.drawPoint( o.x(), o.y() );
86  }
87  }
88 
89  // FIXME: there must be better way to this. Without bothering LocationDialog
90  if( ld ) {
91  //redraw the cities that appear in the filtered list, with a white pen
92  //If the list has not been filtered, skip the redraw.
93  if ( ld->filteredList().size() ) {
94  p.setPen( Qt::white );
95  foreach ( GeoLocation *g, ld->filteredList() ) {
96  o.setX( int( g->lng()->Degrees() + origin.x() ) );
97  o.setY( height() - int( g->lat()->Degrees() + origin.y() ) );
98 
99  if ( o.x() >= 0 && o.x() <= width() && o.y() >=0 && o.y() <=height() ) {
100  p.drawPoint( o.x(), o.y() );
101  }
102  }
103  }
104 
105  GeoLocation *g = ld->selectedCity();
106  if ( g ) {
107  o.setX( int( g->lng()->Degrees() + origin.x() ) );
108  o.setY( height() - int( g->lat()->Degrees() + origin.y() ) );
109 
110  p.setPen( Qt::red );
111  p.setBrush( Qt::red );
112  p.drawEllipse( o.x()-3, o.y()-3, 6, 6 );
113  p.drawLine( o.x()-16, o.y(), o.x()-8, o.y() );
114  p.drawLine( o.x()+8, o.y(), o.x()+16, o.y() );
115  p.drawLine( o.x(), o.y()-16, o.x(), o.y()-8 );
116  p.drawLine( o.x(), o.y()+8, o.x(), o.y()+16 );
117  p.setPen( Qt::white );
118  p.setBrush( Qt::white );
119  }
120  }
121  p.end();
122 }
123 #include "mapcanvas.moc"
MapCanvas::paintEvent
virtual void paintEvent(QPaintEvent *e)
Draw the map.
Definition: mapcanvas.cpp:70
LocationDialog::findCitiesNear
void findCitiesNear(int longitude, int latitude)
Show only cities within 3 degrees of point specified by arguments.
Definition: locationdialog.cpp:308
QWidget
KStarsData::Instance
static KStarsData * Instance()
Definition: kstarsdata.h:92
dms::Degrees
const double & Degrees() const
Definition: dms.h:98
GeoLocation::lng
const dms * lng() const
Definition: geolocation.h:76
LocationDialog::filteredList
QList< GeoLocation * > filteredList()
Definition: locationdialog.h:79
locationdialog.h
GeoLocation
Contains all relevant information for specifying a location on Earth: City Name, State/Province name...
Definition: geolocation.h:39
MapCanvas::~MapCanvas
~MapCanvas()
Destructor (empty)
Definition: mapcanvas.cpp:45
mapcanvas.h
MapCanvas::mousePressEvent
virtual void mousePressEvent(QMouseEvent *e)
Trim the list of cities so that only those within 2 degrees of the mouse click are shown in the list...
Definition: mapcanvas.cpp:61
GeoLocation::lat
const dms * lat() const
Definition: geolocation.h:79
NaN::ld
const long double ld
Definition: nan.h:37
MapCanvas::setGeometry
virtual void setGeometry(int x, int y, int w, int h)
Set the geometry of the map widget (overloaded from QWidget).
Definition: mapcanvas.cpp:49
LocationDialog::selectedCity
GeoLocation * selectedCity() const
Definition: locationdialog.h:76
kstarsdata.h
MapCanvas::MapCanvas
MapCanvas(QWidget *parent)
Default constructor.
Definition: mapcanvas.cpp:32
QFrame
kstars.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal