Stellarium 0.15.0
StelApp.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2006 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 _STELAPP_HPP_
21 #define _STELAPP_HPP_
22 
23 #include <QString>
24 #include <QObject>
25 
26 // Predeclaration of some classes
27 class StelCore;
28 class StelTextureMgr;
29 class StelObjectMgr;
30 class StelLocaleMgr;
31 class StelModuleMgr;
32 class StelSkyCultureMgr;
33 class StelViewportEffect;
34 class QOpenGLFramebufferObject;
35 class QSettings;
36 class QNetworkAccessManager;
37 class QNetworkReply;
38 class QTimer;
39 class StelLocationMgr;
40 class StelSkyLayerMgr;
41 class StelAudioMgr;
42 class StelVideoMgr;
43 class StelGuiBase;
45 class StelScriptMgr;
46 class StelActionMgr;
47 class StelPropertyMgr;
49 
61 class StelApp : public QObject
62 {
63  Q_OBJECT
64  Q_PROPERTY(bool nightMode READ getVisionModeNight WRITE setVisionModeNight NOTIFY visionNightModeChanged)
65 
66 public:
67  friend class StelAppGraphicsWidget;
68  friend class StelSkyItem;
69 
75  StelApp(QObject* parent=NULL);
76 
78  virtual ~StelApp();
79 
81  void init(QSettings* conf);
83  void deinit();
84 
86  void initPlugIns();
87 
89  void initScriptMgr();
90 
93  static StelApp& getInstance() {Q_ASSERT(singleton); return *singleton;}
94 
97  StelModuleMgr& getModuleMgr() {return *moduleMgr;}
98 
101  StelLocaleMgr& getLocaleMgr() {return *localeMgr;}
102 
105  StelSkyCultureMgr& getSkyCultureMgr() {return *skyCultureMgr;}
106 
109  StelTextureMgr& getTextureManager() {return *textureMgr;}
110 
113  StelLocationMgr& getLocationMgr() {return *planetLocationMgr;}
114 
117  StelObjectMgr& getStelObjectMgr() {return *stelObjectMgr;}
118 
119  StelSkyLayerMgr& getSkyImageMgr() {return *skyImageMgr;}
120 
122  StelAudioMgr* getStelAudioMgr() {return audioMgr;}
123 
125  StelActionMgr* getStelActionManager() {return actionMgr;}
126 
129 
131  StelVideoMgr* getStelVideoMgr() {return videoMgr;}
132 
136  StelCore* getCore() {return core;}
137 
139  QNetworkAccessManager* getNetworkAccessManager() {return networkAccessManager;}
140 
142  void updateI18n();
143 
145  QSettings* getSettings() {return confSettings;}
146 
148  QString getCurrentStelStyle() {return "color";}
149 
151  void update(double deltaTime);
152 
154  // 2014-11: OLD COMMENT? What does a void return?
155  // @return the max squared distance in pixels that any object has travelled since the last update.
156  void draw();
157 
159  void glWindowHasBeenResized(float x, float y, float w, float h);
160 
163  float getDevicePixelsPerPixel() const {return devicePixelsPerPixel;}
164  void setDevicePixelsPerPixel(float dppp);
165 
169  float getGlobalScalingRatio() const {return globalScalingRatio;}
170  void setGlobalScalingRatio(float r) {globalScalingRatio=r;}
171 
173  int getBaseFontSize() const { return baseFontSize; }
174  void setBaseFontSize(int s) { baseFontSize=s; }
175 
177  StelGuiBase* getGui() const {return stelGui;}
180  void setGui(StelGuiBase* b) {stelGui=b;}
181 
182 #ifndef DISABLE_SCRIPTING
183  StelMainScriptAPIProxy* getMainScriptAPIProxy() {return scriptAPIProxy;}
186  StelScriptMgr& getScriptMgr() {return *scriptMgr;}
187 #endif
188 
189  static void initStatic();
190  static void deinitStatic();
191 
196  void removeProgressBar(StelProgressController* p);
197 
200  void setViewportEffect(const QString& effectName);
202  QString getViewportEffect() const;
203 
205  // Scriptable methods
206 public slots:
207 
209  void setVisionModeNight(bool);
211  bool getVisionModeNight() const {return flagNightVision;}
212 
214  void setFlagShowDecimalDegrees(bool b);
216  bool getFlagShowDecimalDegrees() const {return flagShowDecimalDegrees;}
217 
219  bool getFlagSouthAzimuthUsage() const { return flagUseAzimuthFromSouth; }
221  void setFlagSouthAzimuthUsage(bool use) { flagUseAzimuthFromSouth=use; }
222 
229 
230 
233  float getFps() const {return fps;}
234 
236  static double getTotalRunTime();
237 
239  static double getAnimationTime();
240 
243  void reportFileDownloadFinished(QNetworkReply* reply);
244 
246  void quit();
247 signals:
248  void visionNightModeChanged(bool);
249  void colorSchemeChanged(const QString&);
250  void languageChanged();
251 
257  void aboutToQuit();
258 
259 private:
260 
262  void handleClick(class QMouseEvent* event);
264  void handleWheel(class QWheelEvent* event);
266  void handleMove(float x, float y, Qt::MouseButtons b);
268  void handleKeys(class QKeyEvent* event);
270  void handlePinch(qreal scale, bool started);
271 
272  void prepareRenderBuffer();
273  void applyRenderBuffer();
274 
275  // The StelApp singleton
276  static StelApp* singleton;
277 
278  // The associated StelCore instance
279  StelCore* core;
280 
281  // Module manager for the application
282  StelModuleMgr* moduleMgr;
283 
284  // Locale manager for the application
285  StelLocaleMgr* localeMgr;
286 
287  // Sky cultures manager for the application
288  StelSkyCultureMgr* skyCultureMgr;
289 
290  //Actions manager fot the application. Will replace shortcutMgr.
291  StelActionMgr* actionMgr;
292 
293  //Property manager for the application
294  StelPropertyMgr* propMgr;
295 
296  // Textures manager for the application
297  StelTextureMgr* textureMgr;
298 
299  // Manager for all the StelObjects of the program
300  StelObjectMgr* stelObjectMgr;
301 
302  // Manager for the list of observer locations on planets
303  StelLocationMgr* planetLocationMgr;
304 
305  // Main network manager used for the program
306  QNetworkAccessManager* networkAccessManager;
307 
309  void setupNetworkProxy();
310 
311  // The audio manager. Must execute in the main thread.
312  StelAudioMgr* audioMgr;
313 
314  // The video manager. Must execute in the main thread.
315  StelVideoMgr* videoMgr;
316 
317  StelSkyLayerMgr* skyImageMgr;
318 
319 #ifndef DISABLE_SCRIPTING
320  // The script API proxy object (for bridging threads)
321  StelMainScriptAPIProxy* scriptAPIProxy;
322 
323  // The script manager based on Qt script engine
324  StelScriptMgr* scriptMgr;
325 #endif
326 
327 
328 
329  StelGuiBase* stelGui;
330 
331  // Store the ratio between real device pixel in "Device Independent Pixel"
332  // Usually this value is 1, but for a mac with retina screen this will be value 2.
333  float devicePixelsPerPixel;
334 
335  // The scaling ratio to apply on all display elements, like GUI, text etc..
336  float globalScalingRatio;
337 
338  // Used to collect wheel events
339  QTimer * wheelEventTimer;
340 
341  // Accumulated horizontal and vertical wheel event deltas
342  int wheelEventDelta[2];
343 
344  float fps;
345  int frame;
346  double timefr, timeBase; // Used for fps counter
347 
349  bool flagNightVision;
350 
351  QSettings* confSettings;
352 
353  // Define whether the StelApp instance has completed initialization
354  bool initialized;
355 
356  static qint64 startMSecs;
357  static float animationScale;
358 
359  // Temporary variables used to store the last gl window resize
360  // if the core was not yet initialized
361  int saveProjW;
362  int saveProjH;
363 
365  int nbDownloadedFiles;
367  qint64 totalDownloadedSize;
368 
370  int nbUsedCache;
372  qint64 totalUsedCacheSize;
373 
374  QList<StelProgressController*> progressControllers;
375 
376  int baseFontSize;
377 
378  // Framebuffer object used for viewport effects.
379  QOpenGLFramebufferObject* renderBuffer;
380 
381  StelViewportEffect* viewportEffect;
382 
383  bool flagShowDecimalDegrees;
384  // flag to indicate we want calculate azimuth from south towards west (as in old astronomical literature)
385  bool flagUseAzimuthFromSouth;
386 
387 };
388 
389 #endif // _STELAPP_HPP_
Manage the sky background images, including DSS and deep sky objects images.
void setFlagSouthAzimuthUsage(bool use)
Get flag for using calculation of azimuth from south towards west (instead north towards east) ...
Definition: StelApp.hpp:221
StelScriptMgr & getScriptMgr()
Get the script manager.
Definition: StelApp.hpp:186
StelLocationMgr & getLocationMgr()
Get the Location manager to use for managing stored locations.
Definition: StelApp.hpp:113
StelVideoMgr * getStelVideoMgr()
Get the video manager.
Definition: StelApp.hpp:131
bool getFlagShowDecimalDegrees() const
Get flag for showing decimal degree in various places.
Definition: StelApp.hpp:216
A scriptable way to show videos embedded in the screen.
void reportFileDownloadFinished(QNetworkReply *reply)
Report that a download occured.
bool getFlagSouthAzimuthUsage() const
Set flag for using calculation of azimuth from south towards west (instead north towards east) ...
Definition: StelApp.hpp:219
bool getFlagOldAzimuthUsage() const
Set flag for using calculation of azimuth from south towards west (as in older astronomical literatur...
Definition: StelApp.hpp:225
int getBaseFontSize() const
Get the size of font.
Definition: StelApp.hpp:173
void setFlagOldAzimuthUsage(bool use)
Get flag for using calculation of azimuth from south towards west (as in older astronomical literatur...
Definition: StelApp.hpp:228
float getFps() const
Get the current number of frame per second.
Definition: StelApp.hpp:233
void progressBarRemoved(const StelProgressController *)
Called just before a progress bar is removed.
void initScriptMgr()
Registers all loaded StelModules with the ScriptMgr, and queues starting of the startup script...
StelObjectMgr & getStelObjectMgr()
Get the StelObject manager to use for querying from all stellarium objects.
Definition: StelApp.hpp:117
static double getAnimationTime()
Return the scaled time for animated objects.
StelPropertyMgr * getStelPropertyManager()
Return the property manager.
Definition: StelApp.hpp:128
Manage i18n operations such as message translation and date/time localization.
Main class for Stellarium core processing.
Definition: StelCore.hpp:48
Because the core API runs in a different thread to the main program, direct function calls to some cl...
StelModuleMgr & getModuleMgr()
Get the module manager to use for accessing any module loaded in the application. ...
Definition: StelApp.hpp:97
StelTextureMgr & getTextureManager()
Get the texture manager to use for loading textures.
Definition: StelApp.hpp:109
void deinit()
Deinitialize core and all the modules.
Manage the list of available location.
QNetworkAccessManager * getNetworkAccessManager()
Get the common instance of QNetworkAccessManager used in stellarium.
Definition: StelApp.hpp:139
QString getCurrentStelStyle()
Return the currently used style.
Definition: StelApp.hpp:148
void progressBarAdded(const StelProgressController *)
Called just after a progress bar is added.
Abstract class defining the base interface for all GUIs.
Definition: StelGuiBase.hpp:30
StelMainScriptAPIProxy * getMainScriptAPIProxy()
Get the script API proxy (for signal handling)
Definition: StelApp.hpp:184
void setGui(StelGuiBase *b)
Tell the StelApp instance which GUI si currently being used.
Definition: StelApp.hpp:180
void initPlugIns()
Load and initialize external modules (plugins)
StelActionMgr * getStelActionManager()
Get the actions manager to use for managing and editing actions.
Definition: StelApp.hpp:125
void draw()
Draw all registered StelModule in the order defined by the order lists.
void update(double deltaTime)
Update all object according to the deltaTime in seconds.
Allow to apply visual effects on the whole Stellarium viewport.
Manage a collection of StelModules including both core and plugin modules.
QString getViewportEffect() const
Get the type of viewport effect currently used.
void updateI18n()
Update translations, font for GUI and sky everywhere in the program.
Manages the registration of specific object properties with the StelProperty system.
float getGlobalScalingRatio() const
Get the scaling ratio to apply on all display elements, like GUI, text etc.
Definition: StelApp.hpp:169
StelApp(QObject *parent=NULL)
Create and initialize the main Stellarium application.
void quit()
do some cleanup and call QCoreApplication::exit(0)
StelAudioMgr * getStelAudioMgr()
Get the audio manager.
Definition: StelApp.hpp:122
Manage the selection and queries on one or more StelObjects.
Manage scripting in Stellarium.
float getDevicePixelsPerPixel() const
Get the ratio between real device pixel and "Device Independent Pixel".
Definition: StelApp.hpp:163
Manage textures loading.
Maintain the state of a progress bar.
Manage sky cultures for stellarium.
void setVisionModeNight(bool)
Set flag for activating night vision mode.
Manager for StelAction instances. Allows registration of new actions, and finding an existing one by ...
void glWindowHasBeenResized(float x, float y, float w, float h)
Call this when the size of the GL window has changed.
static double getTotalRunTime()
Return the time since when stellarium is running in second.
void setViewportEffect(const QString &effectName)
Define the type of viewport effect to use.
static StelApp & getInstance()
Get the StelApp singleton instance.
Definition: StelApp.hpp:93
virtual ~StelApp()
Deinitialize and destroy the main Stellarium application.
StelSkyCultureMgr & getSkyCultureMgr()
Get the sky cultures manager.
Definition: StelApp.hpp:105
QSettings * getSettings()
Return the main configuration options.
Definition: StelApp.hpp:145
StelGuiBase * getGui() const
Get the GUI instance implementing the abstract GUI interface.
Definition: StelApp.hpp:177
void setFlagShowDecimalDegrees(bool b)
Set flag for showing decimal degree in various places.
Singleton main Stellarium application class.
Definition: StelApp.hpp:61
StelProgressController * addProgressBar()
Add a progression indicator to the GUI (if applicable).
void aboutToQuit()
Called just before we exit Qt mainloop.
StelCore * getCore()
Get the core of the program.
Definition: StelApp.hpp:136
StelLocaleMgr & getLocaleMgr()
Get the locale manager to use for i18n & date/time localization.
Definition: StelApp.hpp:101
void init(QSettings *conf)
Initialize core and all the modules.
bool getVisionModeNight() const
Get flag for activating night vision mode.
Definition: StelApp.hpp:211