1 /* 2 * Stellarium 3 * Copyright (C) 2008 Guillaume Chereau 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License 7 * as published by the Free Software Foundation; either version 2 8 * of the License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 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 17 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. 18 */ 19 20 #ifndef LOCATIONDIALOG_HPP 21 #define LOCATIONDIALOG_HPP 22 23 #include <QObject> 24 #include "StelDialog.hpp" 25 26 class Ui_locationDialogForm; 27 class QModelIndex; 28 class QSortFilterProxyModel; 29 class QStringListModel; 30 class StelLocation; 31 32 class LocationDialog : public StelDialog 33 { 34 Q_OBJECT 35 public: 36 LocationDialog(QObject* parent); 37 virtual ~LocationDialog() Q_DECL_OVERRIDE; 38 //! Notify that the application style changed 39 virtual void styleChanged() Q_DECL_OVERRIDE; 40 41 public slots: 42 virtual void retranslate() Q_DECL_OVERRIDE; 43 //! In addition to StelDialog's inherited solution, puts the arrow on the right spot in the map. 44 virtual void handleDialogSizeChanged(QSizeF size) Q_DECL_OVERRIDE; 45 46 protected: 47 //! Initialize the dialog widgets and connect the signals/slots 48 virtual void createDialogContent() Q_DECL_OVERRIDE; 49 Ui_locationDialogForm* ui; 50 51 private: 52 //! Set the values of all the fields from a location info 53 //! Also move the observer to this position 54 void setFieldsFromLocation(const StelLocation& loc); 55 56 //! Create a StelLocation instance from the fields 57 StelLocation locationFromFields() const; 58 59 //! True if the user is currently editing a new location 60 bool isEditingNew; 61 62 void disconnectEditSignals(); 63 void connectEditSignals(); 64 65 //! Update the map for the given location. 66 void setMapForLocation(const StelLocation& loc); 67 68 //! Populates the drop-down list of planets. 69 //! The displayed names are localized in the current interface language. 70 //! The original names are kept in the user data field of each QComboBox 71 //! item. 72 void populatePlanetList(); 73 74 //! Populates the drop-down list of regions. 75 //! The displayed names are localized in the current interface language. 76 //! The original names are kept in the user data field of each QComboBox 77 //! item. 78 void populateRegionList(const QString& planet = ""); 79 80 //! Populates the drop-down list of time zones. 81 //! The displayed names are localized in the current interface language. 82 //! The original names are kept in the user data field of each QComboBox 83 //! item. 84 void populateTimeZonesList(); 85 86 //! Populates tooltips for GUI elements. 87 void populateTooltips(); 88 89 private slots: 90 //! Called whenever the StelLocationMgr is updated 91 void reloadLocations(); 92 93 //! To be called when user edits any field 94 void reportEdit(); 95 96 void saveTimeZone(); 97 98 //! Set timezone (to be connected to a signal from StelCore) 99 //! This has to do some GUI element juggling. 100 void setTimezone(QString tz); 101 102 //! Update the widget to make sure it is synchrone if the location is changed programmatically 103 //! This function should be called repeatidly with e.g. a timer 104 void updateFromProgram(const StelLocation& location); 105 106 //! Called when the map is clicked. 107 //! create new list for places nearby and feed into location list box. 108 void setLocationFromMap(double longitude, double latitude); 109 110 //! Called when the user activates an item from the locations list. 111 void setLocationFromList(const QModelIndex& index); 112 113 //! Called when the planet is manually changed. 114 void moveToAnotherPlanet(const QString& text); 115 116 //! Called when latitude/longitude/altitude is modified 117 //! The int argument is required by the Altitude spinbox signal connection, but unused. 118 void setLocationFromCoords(int i=0); 119 120 //! Called when the user clicks on the add to list button 121 void addCurrentLocationToList(); 122 123 //! Called when the user clicks on the delete button 124 void deleteCurrentLocationFromList(); 125 126 //! filter city list to show entries from single region only 127 void filterSitesByRegion(); 128 129 //! reset city list to complete list (may have been reduced to picked list) 130 void resetLocationList(); 131 132 //! called when the user wants get location from network. 133 //! This is actually a toggle setting which will influence Stellarium's behaviour 134 //! on next boot: 135 //! @arg state true to immediately query location and activate auto-query on next launch. 136 //! @arg state false to store current location as startup location. 137 void ipQueryLocation(bool state); 138 139 // Esp. for signals from StelSkyCultureMgr populatePlanetList(QString)140 void populatePlanetList(QString) { populatePlanetList(); } 141 142 void setDisplayFormatForSpins(bool flagDecimalDegrees); 143 144 #ifdef ENABLE_GPS 145 //! called when the user wants to get GPS location from GPSD or directly attached (USB over virtual serial device) GPS device. 146 //! The easiest and cleanest way to get GPS coordinates from a Linux device is via GPSD. 147 //! On Windows (and Mac?), or where GPSD is not available, we must process the NMEA-183 messages and take care of the Serial port. 148 //! The GPS connection stays open (blocking serial GPS device for other programs if not on GPSD) even with the dialog closed, until disabled again. 149 //! @param enable true to start a repeating series of GPS queries, false to stop it. 150 void gpsEnableQueryLocation(bool enable); // Can be toggled by QToolButton 151 //! handle a few GUI elements when GPS query returns. Should be connected to LocationMgr's signal gpsResult(). 152 //! @param success true if location was found 153 void gpsReturn(bool success); 154 //! reset the default string after a short time where the button shows either success or failure of GPS data retrieval. 155 //! To achieve this effect, this should be called by a QTimer. 156 void resetGPSbuttonLabel(); 157 #endif 158 159 //! Called when the user wants to use the current location as default 160 void setDefaultLocation(bool state); 161 162 //! Updates the check state and the enabled/disabled status. 163 void updateTimeZoneControls(bool useCustomTimeZone); 164 165 private: 166 QString lastPlanet; // for caching when switching map 167 QString customTimeZone; // for caching when switching around timezones. 168 QStringListModel* allModel; 169 QStringListModel* pickedModel; 170 QSortFilterProxyModel *proxyModel; 171 #ifdef ENABLE_GPS 172 unsigned int gpsCount; // count received GPS positions (pure GUI eye candy) 173 #endif 174 175 //QPixmap pixmap; 176 177 //! Updates the check state and the enabled/disabled status. 178 void updateDefaultLocationControls(bool currentIsDefault); 179 }; 180 181 #endif // _LOCATIONDIALOG_HPP 182