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;
48 
60 class StelApp : public QObject
61 {
62  Q_OBJECT
63  Q_PROPERTY(bool nightMode READ getVisionModeNight WRITE setVisionModeNight NOTIFY visionNightModeChanged)
64 
65 public:
66  friend class StelAppGraphicsWidget;
67  friend class StelSkyItem;
68 
74  StelApp(QObject* parent=NULL);
75 
77  virtual ~StelApp();
78 
80  void init(QSettings* conf);
82  void deinit();
83 
85  void initPlugIns();
86 
88  void initScriptMgr();
89 
92  static StelApp& getInstance() {Q_ASSERT(singleton); return *singleton;}
93 
96  StelModuleMgr& getModuleMgr() {return *moduleMgr;}
97 
100  StelLocaleMgr& getLocaleMgr() {return *localeMgr;}
101 
104  StelSkyCultureMgr& getSkyCultureMgr() {return *skyCultureMgr;}
105 
108  StelTextureMgr& getTextureManager() {return *textureMgr;}
109 
112  StelLocationMgr& getLocationMgr() {return *planetLocationMgr;}
113 
116  StelObjectMgr& getStelObjectMgr() {return *stelObjectMgr;}
117 
118  StelSkyLayerMgr& getSkyImageMgr() {return *skyImageMgr;}
119 
121  StelAudioMgr* getStelAudioMgr() {return audioMgr;}
122 
124  StelActionMgr* getStelActionManager() {return actionMgr;}
125 
127  StelVideoMgr* getStelVideoMgr() {return videoMgr;}
128 
132  StelCore* getCore() {return core;}
133 
135  QNetworkAccessManager* getNetworkAccessManager() {return networkAccessManager;}
136 
138  void updateI18n();
139 
141  void updateSkyCulture();
142 
144  QSettings* getSettings() {return confSettings;}
145 
147  QString getCurrentStelStyle() {return "color";}
148 
150  void update(double deltaTime);
151 
153  // 2014-11: OLD COMMENT? What does a void return?
154  // @return the max squared distance in pixels that any object has travelled since the last update.
155  void draw();
156 
158  void glWindowHasBeenResized(float x, float y, float w, float h);
159 
162  float getDevicePixelsPerPixel() const {return devicePixelsPerPixel;}
163  void setDevicePixelsPerPixel(float dppp);
164 
168  float getGlobalScalingRatio() const {return globalScalingRatio;}
169  void setGlobalScalingRatio(float r) {globalScalingRatio=r;}
170 
172  int getBaseFontSize() const { return baseFontSize; }
173  void setBaseFontSize(int s) { baseFontSize=s; }
174 
176  StelGuiBase* getGui() const {return stelGui;}
179  void setGui(StelGuiBase* b) {stelGui=b;}
180 
181 #ifndef DISABLE_SCRIPTING
182  StelMainScriptAPIProxy* getMainScriptAPIProxy() {return scriptAPIProxy;}
185  StelScriptMgr& getScriptMgr() {return *scriptMgr;}
186 #endif
187 
188  static void initStatic();
189  static void deinitStatic();
190 
195  void removeProgressBar(StelProgressController* p);
196 
199  void setViewportEffect(const QString& effectName);
201  QString getViewportEffect() const;
202 
204  // Scriptable methods
205 public slots:
206 
208  void setVisionModeNight(bool);
210  bool getVisionModeNight() const {return flagNightVision;}
211 
213  void setFlagShowDecimalDegrees(bool b);
215  bool getFlagShowDecimalDegrees() const {return flagShowDecimalDegrees;}
216 
218  bool getFlagSouthAzimuthUsage() const { return flagUseAzimuthFromSouth; }
220  void setFlagSouthAzimuthUsage(bool use) { flagUseAzimuthFromSouth=use; }
221 
228 
229 
232  float getFps() const {return fps;}
233 
235  static double getTotalRunTime();
236 
238  static double getAnimationTime();
239 
242  void reportFileDownloadFinished(QNetworkReply* reply);
243 
245  void quit();
246 signals:
247  void visionNightModeChanged(bool);
248  void colorSchemeChanged(const QString&);
249  void languageChanged();
250  void skyCultureChanged(const QString&);
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  // Textures manager for the application
294  StelTextureMgr* textureMgr;
295 
296  // Manager for all the StelObjects of the program
297  StelObjectMgr* stelObjectMgr;
298 
299  // Manager for the list of observer locations on planets
300  StelLocationMgr* planetLocationMgr;
301 
302  // Main network manager used for the program
303  QNetworkAccessManager* networkAccessManager;
304 
306  void setupNetworkProxy();
307 
308  // The audio manager. Must execute in the main thread.
309  StelAudioMgr* audioMgr;
310 
311  // The video manager. Must execute in the main thread.
312  StelVideoMgr* videoMgr;
313 
314  StelSkyLayerMgr* skyImageMgr;
315 
316 #ifndef DISABLE_SCRIPTING
317  // The script API proxy object (for bridging threads)
318  StelMainScriptAPIProxy* scriptAPIProxy;
319 
320  // The script manager based on Qt script engine
321  StelScriptMgr* scriptMgr;
322 #endif
323 
324 
325 
326  StelGuiBase* stelGui;
327 
328  // Store the ratio between real device pixel in "Device Independent Pixel"
329  // Usually this value is 1, but for a mac with retina screen this will be value 2.
330  float devicePixelsPerPixel;
331 
332  // The scaling ratio to apply on all display elements, like GUI, text etc..
333  float globalScalingRatio;
334 
335  // Used to collect wheel events
336  QTimer * wheelEventTimer;
337 
338  // Accumulated horizontal and vertical wheel event deltas
339  int wheelEventDelta[2];
340 
341  float fps;
342  int frame;
343  double timefr, timeBase; // Used for fps counter
344 
346  bool flagNightVision;
347 
348  QSettings* confSettings;
349 
350  // Define whether the StelApp instance has completed initialization
351  bool initialized;
352 
353  static qint64 startMSecs;
354  static float animationScale;
355 
356  // Temporary variables used to store the last gl window resize
357  // if the core was not yet initialized
358  int saveProjW;
359  int saveProjH;
360 
362  int nbDownloadedFiles;
364  qint64 totalDownloadedSize;
365 
367  int nbUsedCache;
369  qint64 totalUsedCacheSize;
370 
371  QList<StelProgressController*> progressControllers;
372 
373  int baseFontSize;
374 
375  // Framebuffer object used for viewport effects.
376  QOpenGLFramebufferObject* renderBuffer;
377 
378  StelViewportEffect* viewportEffect;
379 
380  bool flagShowDecimalDegrees;
381  // flag to indicate we want calculate azimuth from south towards west (as in old astronomical literature)
382  bool flagUseAzimuthFromSouth;
383 
384 };
385 
386 #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:220
StelScriptMgr & getScriptMgr()
Get the script manager.
Definition: StelApp.hpp:185
StelLocationMgr & getLocationMgr()
Get the Location manager to use for managing stored locations.
Definition: StelApp.hpp:112
StelVideoMgr * getStelVideoMgr()
Get the video manager.
Definition: StelApp.hpp:127
bool getFlagShowDecimalDegrees() const
Get flag for showing decimal degree in various places.
Definition: StelApp.hpp:215
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:218
bool getFlagOldAzimuthUsage() const
Set flag for using calculation of azimuth from south towards west (as in older astronomical literatur...
Definition: StelApp.hpp:224
int getBaseFontSize() const
Get the size of font.
Definition: StelApp.hpp:172
void setFlagOldAzimuthUsage(bool use)
Get flag for using calculation of azimuth from south towards west (as in older astronomical literatur...
Definition: StelApp.hpp:227
float getFps() const
Get the current number of frame per second.
Definition: StelApp.hpp:232
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...
void updateSkyCulture()
Update and reload sky culture informations everywhere in the program.
StelObjectMgr & getStelObjectMgr()
Get the StelObject manager to use for querying from all stellarium objects.
Definition: StelApp.hpp:116
static double getAnimationTime()
Return the scaled time for animated objects.
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:96
StelTextureMgr & getTextureManager()
Get the texture manager to use for loading textures.
Definition: StelApp.hpp:108
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:135
QString getCurrentStelStyle()
Return the currently used style.
Definition: StelApp.hpp:147
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:183
void setGui(StelGuiBase *b)
Tell the StelApp instance which GUI si currently being used.
Definition: StelApp.hpp:179
void initPlugIns()
Load and initialize external modules (plugins)
StelActionMgr * getStelActionManager()
Get the actions manager to use for managing and editing actions.
Definition: StelApp.hpp:124
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.
float getGlobalScalingRatio() const
Get the scaling ratio to apply on all display elements, like GUI, text etc.
Definition: StelApp.hpp:168
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:121
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:162
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.
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:92
virtual ~StelApp()
Deinitialize and destroy the main Stellarium application.
StelSkyCultureMgr & getSkyCultureMgr()
Get the sky cultures manager.
Definition: StelApp.hpp:104
QSettings * getSettings()
Return the main configuration options.
Definition: StelApp.hpp:144
StelGuiBase * getGui() const
Get the GUI instance implementing the abstract GUI interface.
Definition: StelApp.hpp:176
void setFlagShowDecimalDegrees(bool b)
Set flag for showing decimal degree in various places.
Singleton main Stellarium application class.
Definition: StelApp.hpp:60
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:132
StelLocaleMgr & getLocaleMgr()
Get the locale manager to use for i18n & date/time localization.
Definition: StelApp.hpp:100
void init(QSettings *conf)
Initialize core and all the modules.
bool getVisionModeNight() const
Get flag for activating night vision mode.
Definition: StelApp.hpp:210