Stellarium 0.13.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 "config.h"
24 #include <QString>
25 #include <QObject>
26 
27 // Predeclaration of some classes
28 class StelCore;
29 class StelTextureMgr;
30 class StelObjectMgr;
31 class StelLocaleMgr;
32 class StelModuleMgr;
33 class StelSkyCultureMgr;
34 class QSettings;
35 class QNetworkAccessManager;
36 class QNetworkReply;
37 class QTime;
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 
89  static StelApp& getInstance() {Q_ASSERT(singleton); return *singleton;}
90 
93  StelModuleMgr& getModuleMgr() {return *moduleMgr;}
94 
97  StelLocaleMgr& getLocaleMgr() {return *localeMgr;}
98 
101  StelSkyCultureMgr& getSkyCultureMgr() {return *skyCultureMgr;}
102 
105  StelTextureMgr& getTextureManager() {return *textureMgr;}
106 
109  StelLocationMgr& getLocationMgr() {return *planetLocationMgr;}
110 
113  StelObjectMgr& getStelObjectMgr() {return *stelObjectMgr;}
114 
115  StelSkyLayerMgr& getSkyImageMgr() {return *skyImageMgr;}
116 
118  StelAudioMgr* getStelAudioMgr() {return audioMgr;}
119 
121  StelActionMgr* getStelActionManager() {return actionMgr;}
122 
124  StelVideoMgr* getStelVideoMgr() {return videoMgr;}
125 
129  StelCore* getCore() {return core;}
130 
132  QNetworkAccessManager* getNetworkAccessManager() {return networkAccessManager;}
133 
135  void updateI18n();
136 
138  void updateSkyCulture();
139 
141  QSettings* getSettings() {return confSettings;}
142 
144  QString getCurrentStelStyle() {return "color";}
145 
147  void update(double deltaTime);
148 
151  void draw();
152 
157  bool drawPartial();
158 
160  void glWindowHasBeenResized(float x, float y, float w, float h);
161 
164  float getDevicePixelsPerPixel() const {return devicePixelsPerPixel;}
165  void setDevicePixelsPerPixel(float dppp);
166 
170  float getGlobalScalingRatio() const {return globalScalingRatio;}
171  void setGlobalScalingRatio(float r) {globalScalingRatio=r;}
172 
174  StelGuiBase* getGui() const {return stelGui;}
177  void setGui(StelGuiBase* b) {stelGui=b;}
178 
179 #ifndef DISABLE_SCRIPTING
180  StelMainScriptAPIProxy* getMainScriptAPIProxy() {return scriptAPIProxy;}
183  StelScriptMgr& getScriptMgr() {return *scriptMgr;}
184 #endif
185 
186  static void initStatic();
187  static void deinitStatic();
188 
193  void removeProgressBar(StelProgressController* p);
194 
196  // Scriptable methods
197 public slots:
198 
200  void setVisionModeNight(bool);
202  bool getVisionModeNight() const {return flagNightVision;}
203 
206  float getFps() const {return fps;}
207 
209  static double getTotalRunTime();
210 
213  void reportFileDownloadFinished(QNetworkReply* reply);
214 
215 signals:
216  void visionNightModeChanged(bool);
217  void colorSchemeChanged(const QString&);
218  void languageChanged();
219  void skyCultureChanged(const QString&);
220 
225 
226 private:
227 
229  void handleClick(class QMouseEvent* event);
231  void handleWheel(class QWheelEvent* event);
233  void handleMove(int x, int y, Qt::MouseButtons b);
235  void handleKeys(class QKeyEvent* event);
236 
237  void initScriptMgr(QSettings* conf);
238 
239  // The StelApp singleton
240  static StelApp* singleton;
241 
242  // The associated StelCore instance
243  StelCore* core;
244 
245  // Module manager for the application
246  StelModuleMgr* moduleMgr;
247 
248  // Locale manager for the application
249  StelLocaleMgr* localeMgr;
250 
251  // Sky cultures manager for the application
252  StelSkyCultureMgr* skyCultureMgr;
253 
254  //Actions manager fot the application. Will replace shortcutMgr.
255  StelActionMgr* actionMgr;
256 
257  // Textures manager for the application
258  StelTextureMgr* textureMgr;
259 
260  // Manager for all the StelObjects of the program
261  StelObjectMgr* stelObjectMgr;
262 
263  // Manager for the list of observer locations on planets
264  StelLocationMgr* planetLocationMgr;
265 
266  // Main network manager used for the program
267  QNetworkAccessManager* networkAccessManager;
268 
270  void setupHttpProxy();
271 
272  // The audio manager. Must execute in the main thread.
273  StelAudioMgr* audioMgr;
274 
275  // The video manager. Must execute in the main thread.
276  StelVideoMgr* videoMgr;
277 
278  StelSkyLayerMgr* skyImageMgr;
279 
280 #ifndef DISABLE_SCRIPTING
281  // The script API proxy object (for bridging threads)
282  StelMainScriptAPIProxy* scriptAPIProxy;
283 
284  // The script manager based on Qt script engine
285  StelScriptMgr* scriptMgr;
286 #endif
287 
288 
289 
290  StelGuiBase* stelGui;
291 
292  // Store the ratio between real device pixel in "Device Independent Pixel"
293  // Usually this value is 1, but for a mac with retina screen this will be value 2.
294  float devicePixelsPerPixel;
295 
296  // The scaling ratio to apply on all display elements, like GUI, text etc..
297  float globalScalingRatio;
298 
299  // Used to collect wheel events
300  QTimer * wheelEventTimer;
301 
302  float fps;
303  int frame;
304  double timefr, timeBase; // Used for fps counter
305 
307  bool flagNightVision;
308 
309  QSettings* confSettings;
310 
311  // Define whether the StelApp instance has completed initialization
312  bool initialized;
313 
314  static QTime* qtime;
315 
316  // Temporary variables used to store the last gl window resize
317  // if the core was not yet initialized
318  int saveProjW;
319  int saveProjH;
320 
322  int nbDownloadedFiles;
324  qint64 totalDownloadedSize;
325 
327  int nbUsedCache;
329  qint64 totalUsedCacheSize;
330 
332  int drawState;
333 
334  QList<StelProgressController*> progressControllers;
335 };
336 
337 #endif // _STELAPP_HPP_
Manage the sky background images, including DSS and deep sky objects images.
Definition: StelSkyLayerMgr.hpp:33
StelScriptMgr & getScriptMgr()
Get the script manager.
Definition: StelApp.hpp:183
StelLocationMgr & getLocationMgr()
Get the Location manager to use for managing stored locations.
Definition: StelApp.hpp:109
StelVideoMgr * getStelVideoMgr()
Get the video manager.
Definition: StelApp.hpp:124
Definition: StelVideoMgr.hpp:26
void reportFileDownloadFinished(QNetworkReply *reply)
Report that a download occured.
float getFps() const
Get the current number of frame per second.
Definition: StelApp.hpp:206
void progressBarRemoved(const StelProgressController *)
Called just before a progress bar is removed.
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:113
Manage i18n operations such as message translation and date/time localization.
Definition: StelLocaleMgr.hpp:28
Main class for Stellarium core processing.
Definition: StelCore.hpp:46
Because the core API runs in a different thread to the main program, direct function calls to some cl...
Definition: StelMainScriptAPIProxy.hpp:44
StelModuleMgr & getModuleMgr()
Get the module manager to use for accessing any module loaded in the application. ...
Definition: StelApp.hpp:93
StelTextureMgr & getTextureManager()
Get the texture manager to use for loading textures.
Definition: StelApp.hpp:105
void deinit()
Deinitialize core and all the modules.
Manage the list of available location.
Definition: StelLocationMgr.hpp:32
QNetworkAccessManager * getNetworkAccessManager()
Get the common instance of QNetworkAccessManager used in stellarium.
Definition: StelApp.hpp:132
QString getCurrentStelStyle()
Return the currently used style.
Definition: StelApp.hpp:144
void progressBarAdded(const StelProgressController *)
Called just after a progress bar is added.
Abstract class defining the base interface for all GUIs.
Definition: StelGuiBase.hpp:32
StelMainScriptAPIProxy * getMainScriptAPIProxy()
Get the script API proxy (for signal handling)
Definition: StelApp.hpp:181
void setGui(StelGuiBase *b)
Tell the StelApp instance which GUI si currently being used.
Definition: StelApp.hpp:177
void initPlugIns()
Load and initialize external modules (plugins)
StelActionMgr * getStelActionManager()
Get the actions manager to use for managing and editing actions.
Definition: StelApp.hpp:121
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.
Manage a collection of StelModules including both core and plugin modules.
Definition: StelModuleMgr.hpp:36
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:170
StelApp(QObject *parent=NULL)
Create and initialize the main Stellarium application.
StelAudioMgr * getStelAudioMgr()
Get the audio manager.
Definition: StelApp.hpp:118
Manage the selection and queries on one or more StelObjects.
Definition: StelObjectMgr.hpp:36
Manage scripting in Stellarium.
Definition: StelScriptMgr.hpp:39
float getDevicePixelsPerPixel() const
Get the ratio between real device pixel and "Device Independent Pixel".
Definition: StelApp.hpp:164
Manage textures loading.
Definition: StelTextureMgr.hpp:33
Maintain the state of a progress bar.
Definition: StelProgressController.hpp:27
Manage sky cultures for stellarium.
Definition: StelSkyCultureMgr.hpp:45
void setVisionModeNight(bool)
Set flag for activating night vision mode.
Definition: StelActionMgr.hpp:101
Definition: StelAudioMgr.hpp:28
bool drawPartial()
Iterate through the drawing sequence.
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.
static StelApp & getInstance()
Get the StelApp singleton instance.
Definition: StelApp.hpp:89
virtual ~StelApp()
Deinitialize and destroy the main Stellarium application.
StelSkyCultureMgr & getSkyCultureMgr()
Get the sky cultures manager.
Definition: StelApp.hpp:101
QSettings * getSettings()
Return the main configuration options.
Definition: StelApp.hpp:141
StelGuiBase * getGui() const
Get the GUI instance implementing the abstract GUI interface.
Definition: StelApp.hpp:174
Singleton main Stellarium application class.
Definition: StelApp.hpp:60
StelProgressController * addProgressBar()
Add a progression indicator to the GUI (if applicable).
StelCore * getCore()
Get the core of the program.
Definition: StelApp.hpp:129
StelLocaleMgr & getLocaleMgr()
Get the locale manager to use for i18n & date/time localization.
Definition: StelApp.hpp:97
void init(QSettings *conf)
Initialize core and all the modules.
bool getVisionModeNight() const
Get flag for activating night vision mode.
Definition: StelApp.hpp:202