1 /* 2 * Stellarium 3 * Copyright (C) 2008 Fabien 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 STELGUI_HPP 21 #define STELGUI_HPP 22 23 #ifndef NO_GUI 24 25 #include "StelModule.hpp" 26 #include "StelObject.hpp" 27 #include "StelGuiBase.hpp" 28 #include "StelStyle.hpp" 29 30 #include <QGraphicsTextItem> 31 32 class QGraphicsSceneMouseEvent; 33 class QTimeLine; 34 class StelButton; 35 class BottomStelBar; 36 class InfoPanel; 37 class ConfigurationDialog; 38 class DateTimeDialog; 39 class HelpDialog; 40 class LocationDialog; 41 class SearchDialog; 42 class ViewDialog; 43 class ShortcutsDialog; 44 class AstroCalcDialog; 45 class ObsListDialog; 46 #ifdef ENABLE_SCRIPT_CONSOLE 47 class ScriptConsole; 48 #endif 49 50 //! @class StelGui 51 //! Main class for the GUI based on QGraphicView. 52 //! It manages the various qt configuration windows, the buttons bars, the list of shortcuts. 53 class StelGui : public QObject, public StelGuiBase 54 { 55 Q_OBJECT 56 Q_PROPERTY(bool visible READ getVisible WRITE setVisible NOTIFY visibleChanged) 57 Q_PROPERTY(bool autoHideHorizontalButtonBar READ getAutoHideHorizontalButtonBar WRITE setAutoHideHorizontalButtonBar NOTIFY autoHideHorizontalButtonBarChanged) 58 Q_PROPERTY(bool autoHideVerticalButtonBar READ getAutoHideVerticalButtonBar WRITE setAutoHideVerticalButtonBar NOTIFY autoHideVerticalButtonBarChanged) 59 Q_PROPERTY(bool flagShowQuitButton READ getFlagShowQuitButton WRITE setFlagShowQuitButton NOTIFY flagShowQuitButtonChanged) 60 Q_PROPERTY(bool flagShowFlipButtons READ getFlagShowFlipButtons WRITE setFlagShowFlipButtons NOTIFY flagShowFlipButtonsChanged) 61 Q_PROPERTY(bool flagShowNebulaBackgroundButton READ getFlagShowNebulaBackgroundButton WRITE setFlagShowNebulaBackgroundButton NOTIFY flagShowNebulaBackgroundButtonChanged) 62 Q_PROPERTY(bool flagShowDSSButton READ getFlagShowDSSButton WRITE setFlagShowDSSButton NOTIFY flagShowDSSButtonChanged) 63 Q_PROPERTY(bool flagShowHiPSButton READ getFlagShowHiPSButton WRITE setFlagShowHiPSButton NOTIFY flagShowHiPSButtonChanged) 64 Q_PROPERTY(bool flagShowGotoSelectedObjectButton READ getFlagShowGotoSelectedObjectButton WRITE setFlagShowGotoSelectedObjectButton NOTIFY flagShowGotoSelectedObjectButtonChanged) 65 Q_PROPERTY(bool flagShowNightmodeButton READ getFlagShowNightmodeButton WRITE setFlagShowNightmodeButton NOTIFY flagShowNightmodeButtonChanged) 66 Q_PROPERTY(bool flagShowFullscreenButton READ getFlagShowFullscreenButton WRITE setFlagShowFullscreenButton NOTIFY flagShowFullscreenButtonChanged) 67 Q_PROPERTY(bool flagShowObsListButton READ getFlagShowObsListButton WRITE setFlagShowObsListButton NOTIFY flagShowObsListButtonChanged) 68 Q_PROPERTY(bool flagShowICRSGridButton READ getFlagShowICRSGridButton WRITE setFlagShowICRSGridButton NOTIFY flagShowICRSGridButtonChanged) 69 Q_PROPERTY(bool flagShowGalacticGridButton READ getFlagShowGalacticGridButton WRITE setFlagShowGalacticGridButton NOTIFY flagShowGalacticGridButtonChanged ) 70 Q_PROPERTY(bool flagShowEclipticGridButton READ getFlagShowEclipticGridButton WRITE setFlagShowEclipticGridButton NOTIFY flagShowEclipticGridButtonChanged ) 71 Q_PROPERTY(bool flagShowConstellationBoundariesButton READ getFlagShowConstellationBoundariesButton WRITE setFlagShowConstellationBoundariesButton NOTIFY flagShowConstellationBoundariesButtonChanged ) 72 Q_PROPERTY(bool flagShowAsterismLinesButton READ getFlagShowAsterismLinesButton WRITE setFlagShowAsterismLinesButton NOTIFY flagShowAsterismLinesButtonChanged ) 73 Q_PROPERTY(bool flagShowAsterismLabelsButton READ getFlagShowAsterismLabelsButton WRITE setFlagShowAsterismLabelsButton NOTIFY flagShowAsterismLabelsButtonChanged ) 74 Q_PROPERTY(bool flagUseButtonsBackground READ getFlagUseButtonsBackground WRITE setFlagUseButtonsBackground NOTIFY flagUseButtonsBackgroundChanged) 75 Q_PROPERTY(bool flagUseKineticScrolling READ getFlagUseKineticScrolling WRITE setFlagUseKineticScrolling NOTIFY flagUseKineticScrollingChanged) 76 Q_PROPERTY(bool flagEnableFocusOnDaySpinner READ getFlagEnableFocusOnDaySpinner WRITE setFlagEnableFocusOnDaySpinner NOTIFY flagEnableFocusOnDaySpinnerChanged) 77 Q_PROPERTY(bool flagShowCardinalButton READ getFlagShowCardinalButton WRITE setFlagShowCardinalButton NOTIFY flagShowCardinalButtonChanged) 78 Q_PROPERTY(bool flagShowCompassButton READ getFlagShowCompassButton WRITE setFlagShowCompassButton NOTIFY flagShowCompassButtonChanged) 79 80 public: 81 friend class ViewDialog; 82 83 StelGui(); 84 virtual ~StelGui() Q_DECL_OVERRIDE; 85 86 /////////////////////////////////////////////////////////////////////////// 87 // Methods defined in the StelModule class 88 //! Initialize the StelGui object. 89 virtual void init(QGraphicsWidget* topLevelGraphicsWidget) Q_DECL_OVERRIDE; 90 void update(); 91 getStelStyle() const92 StelStyle getStelStyle() const {return currentStelStyle;} 93 94 /////////////////////////////////////////////////////////////////////////// 95 // Methods specific to the StelGui class 96 //! Load a Qt style sheet to define the widgets style 97 void loadStyle(const QString& fileName); 98 99 //! Get the button bar at the bottom of the screen 100 BottomStelBar* getButtonBar() const; 101 102 //! Get the button bar of the left of the screen 103 class LeftStelBar* getWindowsButtonBar() const; 104 105 //! Get the SkyGui instance (useful for adding other interface elements). 106 //! It will return a valid object only if called after init(). 107 class SkyGui* getSkyGui() const; 108 109 //! returns true if the gui has completed init process. 110 bool initComplete(void) const; 111 112 #ifdef ENABLE_SCRIPT_CONSOLE getScriptConsole() const113 ScriptConsole* getScriptConsole() const {return scriptConsole;} 114 #endif 115 116 //! Used to force a refreshing of the GUI elements such as the button bars. 117 virtual void forceRefreshGui() Q_DECL_OVERRIDE; 118 119 virtual void setVisible(bool b) Q_DECL_OVERRIDE; 120 121 virtual bool getVisible() const Q_DECL_OVERRIDE; 122 123 virtual bool getAstroCalcVisible() const; 124 125 virtual bool isCurrentlyUsed() const Q_DECL_OVERRIDE; 126 127 virtual void setInfoTextFilters(const StelObject::InfoStringGroup& aflags) Q_DECL_OVERRIDE; 128 virtual const StelObject::InfoStringGroup& getInfoTextFilters() const Q_DECL_OVERRIDE; 129 130 public slots: 131 //! Set the state of the flag of usage background for GUI buttons 132 void setFlagUseButtonsBackground(bool b); 133 //! Get the state of the flag of usage background for GUI buttons getFlagUseButtonsBackground() const134 bool getFlagUseButtonsBackground() const { return flagUseButtonsBackground; } 135 136 //! Set the state of the flag for kinetic scrolling 137 void setFlagUseKineticScrolling(bool b); 138 //! Get the state of the flag for kinetic scrolling getFlagUseKineticScrolling() const139 bool getFlagUseKineticScrolling() const { return flagUseKineticScrolling; } 140 141 //! Set the state of the flag for enable focus on day spinner in Date and Time dialog 142 void setFlagEnableFocusOnDaySpinner(bool b); 143 //! Get the state of the flag for enable focus on day spinner in Date and Time dialog getFlagEnableFocusOnDaySpinner() const144 bool getFlagEnableFocusOnDaySpinner() const { return flagEnableFocusOnDaySpinner; } 145 146 //! Define whether the button for exit should be visible 147 void setFlagShowQuitButton(bool b); 148 //! Get whether the exit button is visible 149 bool getFlagShowQuitButton() const; 150 151 //! Define whether the buttons toggling image flip should be visible 152 void setFlagShowFlipButtons(bool b); 153 //! Get whether the buttons toggling image flip are visible 154 bool getFlagShowFlipButtons() const; 155 156 //! Define whether the button toggling nebulae background should be visible 157 void setFlagShowNebulaBackgroundButton(bool b); 158 //! Get whether the button toggling nebulae background is visible 159 bool getFlagShowNebulaBackgroundButton() const; 160 161 //! Define whether the button toggling DSS survey (TOAST) should be visible 162 void setFlagShowDSSButton(bool b); 163 //! Get whether the button toggling DSS survey (TOAST) is visible 164 bool getFlagShowDSSButton() const; 165 166 //! Define whether the button toggling cardinal should be visible 167 void setFlagShowCardinalButton(bool b); 168 //! Get whether the button toggling cardinal is visible 169 bool getFlagShowCardinalButton() const; 170 171 //! Define whether the button toggling compass marks should be visible 172 void setFlagShowCompassButton(bool b); 173 //! Get whether the button toggling compass marks is visible 174 bool getFlagShowCompassButton() const; 175 176 //! Define whether the button toggling HiPS surveys should be visible 177 void setFlagShowHiPSButton(bool b); 178 //! Get whether the button toggling HiPS surveys is visible 179 bool getFlagShowHiPSButton() const; 180 181 //! Define whether the button for centering on selected object should be visible. If not, user can still press SPACE to center. 182 void setFlagShowGotoSelectedObjectButton(bool b); 183 //! Get whether the button for centering on selected object is visible 184 bool getFlagShowGotoSelectedObjectButton() const; 185 186 //! Define whether the button toggling nightmode should be visible in addition to the Ctrl+N hotkey. 187 void setFlagShowNightmodeButton(bool b); 188 //! Get whether the button toggling nightmode is visible 189 bool getFlagShowNightmodeButton() const; 190 191 //! Define whether the button toggling fullscreen view should be visible in addition to F11 hotkey. 192 void setFlagShowFullscreenButton(bool b); 193 //! Get whether the button toggling fullscreen view is visible 194 bool getFlagShowFullscreenButton() const; 195 196 //! Define whether the button toggling observing list should be visible 197 void setFlagShowObsListButton(bool b); 198 //! Get whether the button toggling observing list is visible 199 bool getFlagShowObsListButton() const; 200 201 //! Define whether the button toggling ICRS grid should be visible 202 void setFlagShowICRSGridButton(bool b); 203 //! Get whether the button toggling ICRS grid is visible 204 bool getFlagShowICRSGridButton() const; 205 206 //! Define whether the button toggling galactic grid should be visible 207 void setFlagShowGalacticGridButton(bool b); 208 //! Get whether the button toggling galactic grid is visible 209 bool getFlagShowGalacticGridButton() const; 210 211 //! Define whether the button toggling ecliptic grid should be visible 212 void setFlagShowEclipticGridButton(bool b); 213 //! Get whether the button toggling ecliptic grid is visible 214 bool getFlagShowEclipticGridButton() const; 215 216 //! Define whether the button toggling constellation boundaries should be visible 217 void setFlagShowConstellationBoundariesButton(bool b); 218 //! Get whether the button toggling constellation boundaries is visible 219 bool getFlagShowConstellationBoundariesButton() const; 220 221 //! Define whether the button toggling asterism lines should be visible 222 void setFlagShowAsterismLinesButton(bool b); 223 //! Get whether the button toggling asterism lines is visible 224 bool getFlagShowAsterismLinesButton() const; 225 226 //! Define whether the button toggling asterism labels should be visible 227 void setFlagShowAsterismLabelsButton(bool b); 228 //! Get whether the button toggling asterism labels is visible 229 bool getFlagShowAsterismLabelsButton() const; 230 231 //! Get the auto-hide status of the horizontal toolbar. 232 bool getAutoHideHorizontalButtonBar() const; 233 //! Set the auto-hide status of the horizontal toolbar. 234 //! When set to true, the horizontal toolbar will auto-hide itself, only 235 //! making an appearance when the mouse is nearby. When false, it will 236 //! remain on screen. 237 //! @param b to hide or not to hide 238 void setAutoHideHorizontalButtonBar(bool b); 239 240 //! Get the auto-hide status of the vertical toolbar. 241 bool getAutoHideVerticalButtonBar() const; 242 //! Set the auto-hide status of the vertical toolbar. 243 //! When set to true, the vertical toolbar will auto-hide itself, only 244 //! making an appearance when the mouse is nearby. When false, it will 245 //! remain on screen. 246 //! @param b to hide or not to hide 247 void setAutoHideVerticalButtonBar(bool b); 248 249 #ifdef ENABLE_SCRIPTING 250 //! change keys when a script is running / not running 251 void setScriptKeys(bool b); 252 void increaseScriptSpeed(); 253 void decreaseScriptSpeed(); 254 void setRealScriptSpeed(); 255 void stopScript(); 256 void pauseScript(); 257 void resumeScript(); 258 #endif 259 260 //! Hide or show the GUI. Public so it can be called from scripts. 261 void setGuiVisible(bool); 262 263 signals: 264 void visibleChanged(bool b); 265 void autoHideHorizontalButtonBarChanged(bool b); 266 void autoHideVerticalButtonBarChanged(bool b); 267 void flagUseButtonsBackgroundChanged(bool b); 268 void flagUseKineticScrollingChanged(bool b); 269 void flagEnableFocusOnDaySpinnerChanged(bool b); 270 void flagShowQuitButtonChanged(bool b); 271 void flagShowFlipButtonsChanged(bool b); 272 void flagShowNebulaBackgroundButtonChanged(bool b); 273 void flagShowDSSButtonChanged(bool b); 274 void flagShowHiPSButtonChanged(bool b); 275 void flagShowGotoSelectedObjectButtonChanged(bool b); 276 void flagShowNightmodeButtonChanged(bool b); 277 void flagShowFullscreenButtonChanged(bool b); 278 void flagShowObsListButtonChanged(bool b); 279 void flagShowICRSGridButtonChanged(bool b); 280 void flagShowGalacticGridButtonChanged(bool b); 281 void flagShowEclipticGridButtonChanged(bool b); 282 void flagShowConstellationBoundariesButtonChanged(bool b); 283 void flagShowAsterismLinesButtonChanged(bool b); 284 void flagShowAsterismLabelsButtonChanged(bool b); 285 void flagShowCardinalButtonChanged(bool b); 286 void flagShowCompassButtonChanged(bool b); 287 288 private slots: 289 void reloadStyle(); 290 #ifdef ENABLE_SCRIPTING 291 void scriptStarted(); 292 void scriptStopped(); 293 #endif 294 //! Load color scheme from the given ini file and section name 295 virtual void setStelStyle(const QString& section) Q_DECL_OVERRIDE; 296 void quit(); 297 void updateI18n(); 298 void copySelectedObjectInfo(void); 299 300 private: 301 //! convenience method to find an action in the StelActionMgr. 302 StelAction* getAction(const QString& actionName) const; 303 304 void addButtonOnBottomBar(QString buttonName, QString actionName, QString groupName); 305 void addButtonOnLeftBar(QString buttonName, QString actionName); 306 307 QGraphicsWidget* topLevelGraphicsWidget; 308 309 class SkyGui* skyGui; 310 311 bool flagUseButtonsBackground; 312 bool flagUseKineticScrolling; 313 bool flagEnableFocusOnDaySpinner; 314 315 StelButton* buttonTimeRewind; 316 StelButton* buttonTimeRealTimeSpeed; 317 StelButton* buttonTimeCurrent; 318 StelButton* buttonTimeForward; 319 320 bool flagShowQuitButton; 321 StelButton* buttonQuit; 322 323 bool flagShowGotoSelectedObjectButton; 324 StelButton* buttonGotoSelectedObject; 325 326 LocationDialog* locationDialog; 327 HelpDialog* helpDialog; 328 DateTimeDialog* dateTimeDialog; 329 SearchDialog* searchDialog; 330 ViewDialog* viewDialog; 331 ShortcutsDialog* shortcutsDialog; 332 ConfigurationDialog* configurationDialog; 333 #ifdef ENABLE_SCRIPT_CONSOLE 334 ScriptConsole* scriptConsole; 335 #endif 336 AstroCalcDialog* astroCalcDialog; 337 ObsListDialog* obsListDialog; 338 339 bool flagShowFlipButtons; 340 StelButton* flipVert; 341 StelButton* flipHoriz; 342 343 bool flagShowNebulaBackgroundButton; 344 StelButton* btShowNebulaeBackground; 345 346 bool flagShowDSSButton; 347 StelButton* btShowDSS; 348 349 bool flagShowHiPSButton; 350 StelButton* btShowHiPS; 351 352 bool flagShowNightmodeButton; 353 StelButton* buttonNightmode; 354 355 bool flagShowFullscreenButton; 356 StelButton* buttonFullscreen; 357 358 bool flagShowObsListButton; 359 StelButton* btShowObsList; 360 361 bool flagShowICRSGridButton; 362 StelButton* btShowICRSGrid; 363 364 bool flagShowGalacticGridButton; 365 StelButton* btShowGalacticGrid; 366 367 bool flagShowEclipticGridButton; 368 StelButton* btShowEclipticGrid; 369 370 bool flagShowConstellationBoundariesButton; 371 StelButton* btShowConstellationBoundaries; 372 373 bool flagShowAsterismLinesButton; 374 StelButton* btShowAsterismLines; 375 376 bool flagShowAsterismLabelsButton; 377 StelButton* btShowAsterismLabels; 378 379 bool flagShowCardinalButton; 380 StelButton* btShowCardinal; 381 382 bool flagShowCompassButton; 383 StelButton* btShowCompass; 384 385 bool initDone; 386 387 QSizeF savedProgressBarSize; 388 389 // Currently used StelStyle 390 StelStyle currentStelStyle; 391 392 #ifdef ENABLE_SCRIPTING 393 // We use a QStringList to save the user-configured buttons while script is running, and restore them later. 394 QStringList scriptSaveSpeedbuttons; 395 #endif 396 }; 397 398 #else // NO_GUI 399 400 #include "StelGuiBase.hpp" 401 #include <QProgressBar> 402 403 class StelGui : public StelGuiBase 404 { 405 public: StelGui()406 StelGui() {;} ~StelGui()407 ~StelGui() {;} init(QGraphicsWidget * topLevelGraphicsWidget,class StelAppGraphicsWidget * stelAppGraphicsWidget)408 virtual void init(QGraphicsWidget* topLevelGraphicsWidget, class StelAppGraphicsWidget* stelAppGraphicsWidget) {;} updateI18n()409 virtual void updateI18n() {;} setStelStyle(const QString & section)410 virtual void setStelStyle(const QString& section) {;} setInfoTextFilters(const StelObject::InfoStringGroup & aflags)411 virtual void setInfoTextFilters(const StelObject::InfoStringGroup& aflags) {dummyInfoTextFilter=aflags;} getInfoTextFilters() const412 virtual const StelObject::InfoStringGroup& getInfoTextFilters() const {return dummyInfoTextFilter;} addProgressBar()413 virtual QProgressBar* addProgressBar() {return new QProgressBar;} addGuiActions(const QString & actionName,const QString & text,const QString & shortCut,const QString & helpGroup,bool checkable=true,bool autoRepeat=false)414 virtual QAction* addGuiActions(const QString& actionName, const QString& text, const QString& shortCut, const QString& helpGroup, bool checkable=true, bool autoRepeat=false) {return Q_NULLPTR;} forceRefreshGui()415 virtual void forceRefreshGui() {;} setVisible(bool b)416 virtual void setVisible(bool b) {visible=b;} getVisible() const417 virtual bool getVisible() const {return visible;} isCurrentlyUsed() const418 virtual bool isCurrentlyUsed() const {return false;} 419 private: 420 StelObject::InfoStringGroup dummyInfoTextFilter; 421 bool visible; 422 }; 423 424 #endif 425 426 #endif // STELGUI_HPP 427