File indexing completed on 2024-04-21 03:44:59
0001 /* 0002 SPDX-FileCopyrightText: 2001 Jason Harris <jharris@30doradus.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef MAPCANVAS_H 0008 #define MAPCANVAS_H 0009 0010 #include <QFrame> 0011 #include <QPixmap> 0012 #include <QMouseEvent> 0013 #include <QPaintEvent> 0014 #include <geolocation.h> 0015 0016 /** @class MapCanvas 0017 *Used in LocationDialog for displaying a map of the Earth. 0018 *In addition, cities in the database are drawn as grey or white dots. 0019 *Also, the widget processes mouse clicks, to trim the list of 0020 *cities to those near the mouse click. 0021 *@short Widget used in the LocationDialog for displaying the world map. 0022 *@author Jason Harris 0023 *@version 1.0 0024 */ 0025 0026 class LocationDialog; 0027 class QPixmap; 0028 0029 class MapCanvas : public QFrame 0030 { 0031 Q_OBJECT 0032 public: 0033 /**Default constructor. Initialize the widget: create pixmaps, load the 0034 * world map image 0035 * @param parent pointer to the parent LocationDialog 0036 */ 0037 explicit MapCanvas(QWidget *parent); 0038 0039 /**Destructor (empty) */ 0040 ~MapCanvas() override; 0041 0042 /** Set location dialog */ 0043 // FIXME: This is temporary plug 0044 void setLocationDialog(LocationDialog *loc) { ld = loc; } 0045 public slots: 0046 /**Set the geometry of the map widget (overloaded from QWidget). 0047 * Resizes the size of the map pixmap to match the widget, and resets 0048 * the Origin QPoint so it remains at the center of the widget. 0049 * @note this is called automatically by resize events. 0050 * @p x the x-position of the widget 0051 * @p y the y-position of the widget 0052 * @p w the width of the widget 0053 * @p h the height of the widget 0054 */ 0055 virtual void setGeometry(int x, int y, int w, int h); 0056 0057 /**Set the geometry of the map widget (overloaded from QWidget). 0058 * Resizes the size of the map pixmap to match the widget, and resets 0059 * the Origin QPoint so it remains at the center of the widget. 0060 * This function behaves just like the above function. It differs 0061 * only in the data type of its argument. 0062 * @note this is called automatically by resize events. 0063 * @p r QRect describing geometry 0064 */ 0065 virtual void setGeometry(const QRect &r); 0066 0067 protected: 0068 /**Draw the map. Draw grey dots on the locations of all cities, 0069 * and highlight the cities which match the current filters as 0070 * white dits. Also draw a red crosshairs on the 0071 * currently-selected city. 0072 * @see LocationDialog 0073 */ 0074 void paintEvent(QPaintEvent *e) override; 0075 0076 /**Trim the list of cities so that only those within 2 degrees 0077 * of the mouse click are shown in the list. 0078 * @see LocationDialog 0079 */ 0080 void mousePressEvent(QMouseEvent *e) override; 0081 0082 /**Convert geo co-ordinates to a scaled position on the map*/ 0083 void convertAndScale(QPoint &o, GeoLocation &g); 0084 0085 private: 0086 LocationDialog *ld; 0087 QPixmap *bgImage; 0088 QString BGColor; 0089 QPoint origin; 0090 double xsize; 0091 double ysize; 0092 double ximage; 0093 double yimage; 0094 double ratio; 0095 double xscale; 0096 double yscale; 0097 }; 0098 0099 #endif